Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Tiny snow demo written in ASM for a JS 8-bit ASM simulator
- ; Run in http://schweigi.github.io/assembler-simulator/
- ;
- ; Corné Dorrestijn
- JMP start
- message:
- DB "Merry Xmas & Happy '14"
- start:
- MOV C, 232 ; Point to output
- CALL cls ; Clear the screen, in firefox the 0x00 are
- ; shown, you could disable this on chrome
- CALL demo ; star the snow demo
- DB 0 ; Stop execution
- cls: ; Clear screen
- PUSH A
- PUSH B
- MOV B, 0
- .clear:
- MOV [C], 0x20 ; Write space char (0x20) to output
- INC C
- CMP B, C ; Check if end
- JNZ .clear ; jump if not
- POP B
- POP A
- RET
- demo:
- MOV A, 0 ; Push 0 to A
- MOV D, 0 ; Push 0 to D
- MOV [223], 2 ; D will use this later
- MOV D, message
- .reset:
- ADD A, 13 ; Add prime number (seed for randomness) to A
- .test:
- SUB A, 8 ; Subtract 8
- CMP A, 8 ; Compare A
- JA .test ; If still above 8 repeat test
- MOV C, 231 ; Begin of output
- ADD C, A ; Add A (X position)
- .loop:
- MOV [C], 0x2A ; Write * to output
- SUB C, 8 ; Substract 8 (y--) (this will write outside
- ; the output, but still enough memory)
- MOV [C], 0x20 ; Write whitespace to ouput
- ADD C, 16 ; Add 16 (y + 2)
- INC D ; Increase D (timer for ticker)
- CMP D, 0x1A ; If D is 0x1A start ticker
- JZ .ticker
- .tickerend:
- CMP C, 238 ; Compare if C is above 200
- JBE .reset ; Jump to restet to change X
- JMP .loop ; Jump to loop to change Y
- .ticker:
- MOV D, [223] ; Receive D from memory
- CMP D, [D] ; Compare D with string length
- JNBE .tdone ; If whole string is shown return
- MOV [224], A ; Store A in memory
- MOV B, 240 ; Set B to 240, output address
- .tloop:
- MOV A, [D] ; Get character from string
- MOV [B], A ; Put character to ouput
- INC B; ; Increase B (X pos)
- INC D; ; Increase D (Character from string)
- CMP D, [D] ; Compare D with string length
- JNBE .tdone ; If whole string is shown return
- CMP B, 248 ; Compare B with max width
- JNZ .tloop ; If not there jump to tloop
- SUB D, 7 ; Substract 7 from D
- MOV A, [224] ; Restore A from memory
- .tdone:
- MOV [223], D ; Store D in memory
- MOV D, 0x19 ; Change D to 0x19
- JMP .tickerend ; Jump back to the snow animation
Advertisement
Add Comment
Please, Sign In to add comment