nedoPC.org

Community of electronics hobbyists established in 2002

...
Atom Feed | View unanswered posts | View active topics It is currently 13 Nov 2018 09:41



Reply to topic  [ 3 posts ] 
[ASM] Worm for ZX 
Author Message
Writer

Joined: 06 Sep 2007 08:05
Posts: 19
Location: 212.26.238.228
Reply with quote
Post 
Собственно, вот как оно короче всего получается на ZX Spectrum (через калькулятор). 121 байт. Опубликовано в IG#10.

Ступеньками обозначена глубина стека калькулятора.

Code:
;SNAKE light edition by Alone Coder 19iii2007
;h - left
;k - right
;l - down
;p - up
;mem-0 is used in mod
;mem-0..2 are used in sin
        MACRO INCREMENT
        DB #A1 ;stk-one
        DB #0F ;addition
        ENDM

;POKE=7808=#1E80 (gets A from stack, gets BC with keeping)
        MACRO POKE1ST
        DB #34 ;stk-data
        DB %00111101 ;1 b, EXP=#8D
        DB #74
        DB #CB ;st-mem-11 ;const POKE
        DB #2D ;usr-no
        ENDM

        MACRO POKE
        DB #EB ;get-mem-11 ;const POKE
        DB #2D ;usr-no
        ENDM

        MACRO SCRADDR1ST
       DB #34 ;stk-data ;=32
       DB %00110110 ;1 b, EXP=#86
       DB #00
      DB #C8 ;st-mem-8 ;const 32
      DB #04 ;multiply Y*32
       DB #0F ;addition
        DB #34 ;stk-data ;=#5800
        DB %00111111 ;1 b, EXP=#8F
        DB #30
       DB #CC ;st-mem-12 ;const #5800
       DB #0F ;addition
        ENDM

        MACRO SCRADDR
       DB #E8 ;get-mem-8 ;const 32
      DB #04 ;multiply Y*32
       DB #0F ;addition
        DB #EC ;get-mem-12 ;const #5800
       DB #0F ;addition
        ENDM

        ORG #6000
;attr=0 may be done in BASIC, and these 8 bytes may be killed
        XOR A
        LD H,#5B
clm0    DEC HL
        LD (HL),A
        CP (HL)
        JZ clm0
        RST #28
        DB #34 ;stk-data ;=24
        DB %00110101 ;1 b, EXP=#85
        DB #40
       DB #C9 ;st-mem-9 ;const 24 ;ATRRABB
       DB #C4 ;st-mem-4 ;RABBIT =1
        DB #A0 ;stk-zero
       DB #C5 ;st-mem-5 ;TAIL =0
       DB #C6 ;st-mem-6 ;XPOS =0
       DB #C3 ;st-mem-3 ;YPOS =0
loop
       ;stack:HEAD
        DB #34 ;stk-data ;BUF=#7A00=BUFLEN*4
        DB %00111111 ;1 b, EXP=#8F
        DB #74
       DB #CA ;st-mem-10 ;const BUF
       DB #0F ;addition HEAD+BUF
        DB #E6 ;get-mem-6 ;XPOS
       POKE1ST
        INCREMENT
        DB #E3 ;get-mem-3 ;YPOS
       POKE
        INCREMENT
        DB #EB ;get-mem-11 ;const BUFLEN
       DB #32 ;n-mod-m
       DB #02 ;delete ;BUF/BUFLEN = 4/5
       ;stack:HEAD

        DB #E5 ;get-mem-5 ;TAIL
       DB #E4 ;get-mem-4 ;RABBIT
      DB #30 ;not (1 if RABBIT=0)
      DB #31 ;duplicate
     DB #0F ;addition (2 if RABBIT=0)
      DB #0F ;addition TAIL+0/2
       DB #EB ;get-mem-11 ;const BUFLEN
      DB #32 ;n-mod-m
      DB #02 ;delete ;TAIL/BUFLEN = 4/5
       DB #C5 ;st-mem-5 ;TAIL
      ;stack:HEAD,TAIL

       DB #EA ;get-mem-10 ;const BUF
      DB #0F ;addition TAIL+BUF
       DB #31 ;duplicate ;for peek YPOS
      DB #2B ;peek ;XTAIL
      DB #01 ;exchange ;XPOS,addr
      INCREMENT
      DB #2B ;peek ;YTAIL
      SCRADDR1ST
       DB #E4 ;get-mem-4 ;RABBIT
      POKE
       DB #02 ;delete ;RABBIT SCRADDR
       ;stack:HEAD

        DB #34 ;stk-data ;=#5C08
        DB %01111111 ;2 b, EXP=#8F
        DB #38,#10
       DB #2B ;peek
       DB #C7 ;st-mem-7 ;KEY
       DB #20 ;cos
      DB #E8 ;get-mem-8 ;const 32
      DB #A2 ;stk-half
     DB #0F ;addition
      DB #0F ;addition
       DB #27 ;int
       DB #E6 ;get-mem-6 ;XPOS
      DB #0F ;addition
       DB #E8 ;get-mem-8 ;const 32
      DB #32 ;n-mod-m
      DB #02 ;delete ;XPOS/32 = 0/1/2
       DB #C6 ;st-mem-6 ;XPOS
      ;stack:HEAD,XPOS

       DB #E7 ;get-mem-7 ;KEY
      DB #1F ;sin
     DB #E9 ;get-mem-9 ;const 24
     DB #A2 ;stk-half
    DB #0F ;addition
     DB #0F ;addition
      DB #27 ;int
      DB #E3 ;get-mem-3 ;YPOS
     DB #0F ;addition
      DB #E9 ;get-mem-9 ;const 24
     DB #32 ;n-mod-m
     DB #02 ;delete ;YPOS/24 = 0/1/2
      DB #C3 ;st-mem-3 ;YPOS
      SCRADDR
      ;stack:HEAD,SCRADDR
dieloop
       DB #31 ;duplicate ;for POKE ATRSN
      DB #2B ;peek
      DB #C4 ;st-mem-4 ;RABBIT <>0 (if ATRRABB)
      DB #E8 ;get-mem-8 ;const 32 ;ATRSN
     DB #0E ;nos-eql ;TRUE if =
      DB #00 ;jump-true
      DB dieloop-$
       DB #E8 ;get-mem-8 ;const 32 ;ATRSN
      POKE
       DB #02 ;delete ;HEAD SCRADDR
       ;stack:HEAD
        DB #33 ;jump
        DB loop-$


06 Sep 2007 12:07
Profile
Admin
User avatar

Joined: 09 Jan 2003 00:22
Posts: 17116
Location: Colorado
Reply with quote
Post 
Ух ты - сам Alone Coder к нам пожаловал! :o

P.S. Я перенёс пост из топика Worm для IBM PC сюда

_________________
:eugeek: https://twitter.com/Shaos1973


06 Sep 2007 15:54
Profile WWW
Retired

Joined: 03 Aug 2003 23:37
Posts: 1481
Location: Moscow
Reply with quote
Post 
Shaos wrote:
Ух ты - сам Alone Coder к нам пожаловал! :o

Здорово :D

_________________
Extreme Entertainment


06 Sep 2007 22:52
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.