cornedor

ASM Tiny Xmas Card

Dec 24th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Tiny snow demo written in ASM for a JS 8-bit ASM simulator
  2. ; Run in http://schweigi.github.io/assembler-simulator/
  3. ;
  4. ; Corné Dorrestijn
  5.  
  6. JMP start
  7.  
  8. message:
  9.     DB "Merry Xmas & Happy '14"
  10. start:
  11.     MOV C, 232  ; Point to output
  12.     CALL cls    ; Clear the screen, in firefox the 0x00 are
  13.             ; shown, you could disable this on chrome
  14.     CALL demo   ; star the snow demo
  15.     DB 0        ; Stop execution
  16.  
  17. cls:            ; Clear screen
  18.     PUSH A
  19.     PUSH B
  20.     MOV B, 0
  21. .clear:
  22.     MOV [C], 0x20   ; Write space char (0x20) to output
  23.     INC C
  24.     CMP B, C    ; Check if end
  25.     JNZ .clear  ; jump if not
  26.  
  27.     POP B
  28.     POP A
  29.     RET
  30.  
  31. demo:
  32.     MOV A, 0        ; Push 0 to A
  33.     MOV D, 0        ; Push 0 to D
  34.     MOV [223], 2    ; D will use this later
  35.     MOV D, message
  36.  
  37. .reset:
  38.     ADD A, 13   ; Add prime number (seed for randomness) to A
  39. .test:
  40.     SUB A, 8    ; Subtract 8
  41.     CMP A, 8    ; Compare A
  42.     JA .test    ; If still above 8 repeat test
  43.    
  44.     MOV C, 231  ; Begin of output
  45.     ADD C, A    ; Add A (X position)
  46. .loop:
  47.     MOV [C], 0x2A   ; Write * to output
  48.     SUB C, 8    ; Substract 8 (y--) (this will write outside
  49.             ; the output, but still enough memory)
  50.     MOV [C], 0x20   ; Write whitespace to ouput
  51.     ADD C, 16   ; Add 16 (y + 2)
  52.     INC D       ; Increase D (timer for ticker)
  53.     CMP D, 0x1A ; If D is 0x1A start ticker
  54.     JZ .ticker
  55.  
  56. .tickerend:
  57.     CMP C, 238  ; Compare if C is above 200
  58.     JBE .reset  ; Jump to restet to change X
  59.     JMP .loop   ; Jump to loop to change Y
  60.  
  61. .ticker:
  62.     MOV D, [223]    ; Receive D from memory
  63.     CMP D, [D]  ; Compare D with string length
  64.     JNBE .tdone ; If whole string is shown return
  65.     MOV [224], A    ; Store A in memory
  66.     MOV B, 240  ; Set B to 240, output address
  67.  
  68. .tloop:
  69.     MOV A, [D]  ; Get character from string
  70.     MOV [B], A  ; Put character to ouput
  71.     INC B;      ; Increase B (X pos)
  72.     INC D;      ; Increase D (Character from string)
  73.     CMP D, [D]  ; Compare D with string length
  74.     JNBE .tdone ; If whole string is shown return
  75.     CMP B, 248  ; Compare B with max width
  76.     JNZ .tloop  ; If not there jump to tloop
  77.  
  78.     SUB D, 7    ; Substract 7 from D
  79.     MOV A, [224]    ; Restore A from memory
  80. .tdone:
  81.     MOV [223], D    ; Store D in memory
  82.     MOV D, 0x19 ; Change D to 0x19
  83.     JMP .tickerend  ; Jump back to the snow animation
Advertisement
Add Comment
Please, Sign In to add comment