home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 83 / asm / source / xordemo.z80 < prev    next >
Encoding:
Text File  |  2001-07-01  |  9.4 KB  |  305 lines

  1. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  2. ;│█████ Z80 ██████│  Spr xor demo  │█████████████████████│ movax │████████████│
  3. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  4.  
  5. ; Sprite xor example v1.0
  6. ; Coded by Hannes Edfeldt in 1997
  7.  
  8. ; This little program demonstrates how to use the routine SPRXOR and shows
  9. ; what happens when you use xor to draw and erase sprites.
  10.  
  11. ; Use the graphkeys to alternate between five diffrent speeds, press clear to
  12. ; quit.
  13.  
  14. ; Feel free to use this routine in your own productions as long as you give me
  15. ; some credit.
  16.  
  17. ; This file should of course be viewed in a DOS texteditor ;)
  18.  
  19. ; Hannes Edfeldt -+- movax@algonet.se -+- http://www.algonet.se/~movax
  20.  
  21.         .org     9327h
  22.  
  23. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  24. ;│█████ Z80 ██████│      CODE      │█████████████████████│ movax │████████████│
  25. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  26.  
  27. START:
  28.         call    RINDOFF
  29.         call    BUFCLR
  30.  
  31.         ld      b,88            ; -- Initiate sprite directions
  32.         ld      ix,SPRDIR
  33. DIRLOP: ld      a,r
  34.         srl     a
  35.         and     00000001b
  36.         cp      1
  37.         jp      nz,SKP01
  38.         ld      (ix+0),a
  39.         jp      SKP02
  40. SKP01:  ld      a,-1
  41.         ld      (ix+0),a
  42. SKP02:  inc     ix
  43.         djnz    DIRLOP
  44.  
  45.  
  46. MAIN:
  47.         ld      b,44            ; -- Draw sprites
  48.         ld      ix,SPRCORD
  49.         ld      hl,ALIEN        ; Get address to the alien sprite
  50. SPRLOP: ld      a,(ix+0)        ; Get x-coordinate
  51.         ld      e,(ix+1)        ; Get y-coordinate
  52.         push    bc
  53.         push    hl
  54.         push    ix
  55.         call    SPRXOR          ; Draw the sprite
  56.         pop     ix
  57.         pop     hl
  58.         pop     bc
  59.         inc     ix              ; Make ix point to next sprite's coordinates
  60.         inc     ix
  61.         djnz    SPRLOP
  62.  
  63.  
  64.         ld      a,(SPEED)
  65.         ld      b,a
  66. WAITL1:
  67.         push    bc
  68.         call    BUFCOPY         ; Copy graphbuf to LCD
  69.         pop     bc
  70.         djnz    WAITL1
  71.  
  72.  
  73.         ld      b,44            ; -- Clear sprites
  74.         ld      ix,SPRCORD
  75.         ld      hl,ALIEN        ; Get address to the alien sprite
  76. CLRLOP: ld      a,(ix+0)        ; Get x-coordinate
  77.         ld      e,(ix+1)        ; Get y-coordinate
  78.         push    bc
  79.         push    hl
  80.         push    ix
  81.         call    SPRXOR          ; Clear the sprite
  82.         pop     ix
  83.         pop     hl
  84.         pop     bc
  85.         inc     ix              ; Make ix point to next sprite's coordinates
  86.         inc     ix
  87.         djnz    CLRLOP
  88.  
  89.  
  90.         ld      b,44            ; -- Update sprite directions
  91.         ld      ix,SPRCORD
  92.         ld      hl,SPRDIR
  93.  
  94. CHGDIR: ld      a,(ix+0)
  95.         cp      0               ; Reached left edge?
  96.         jp      nz,SKP03
  97.         ld      a,1
  98.         ld      (hl),a
  99.  
  100. SKP03:  cp      88              ; Reached right edge?
  101.         jp      nz,SKP04
  102.         ld      a,-1
  103.         ld      (hl),a
  104.  
  105. SKP04:  inc     hl
  106.         ld      a,(ix+1)
  107.         cp      0               ; Reached top?
  108.         jp      nz,SKP05
  109.         ld      a,1
  110.         ld      (hl),a
  111.  
  112. SKP05:  cp      56              ; Reached bottom?
  113.         jp      nz,SKP06
  114.         ld      a,-1
  115.         ld      (hl),a
  116.  
  117. SKP06:  inc     ix
  118.         inc     ix
  119.         inc     hl
  120.         djnz    CHGDIR
  121.  
  122.  
  123.         ld      b,88            ; -- Sprite movement
  124.         ld      ix,SPRCORD
  125.         ld      hl,SPRDIR
  126.  
  127. SPRMOV: ld      a,(ix+0)
  128.         add     a,(hl)
  129.         ld      (ix+0),a
  130.         inc     ix
  131.         inc     hl
  132.         djnz    SPRMOV
  133.  
  134.  
  135.         call    READKEY         ; Look for speedchange
  136.         call    OP2TOP1
  137.         call    CONVOP1
  138.         sub     10
  139.         cp      6
  140.         jp      nc,SKP08
  141.         ld      (KEY),a
  142.  
  143. SKP08:  ld      a,(KEY)
  144.         ld      (SPEED),a
  145.  
  146.         ld      a,0ffh          ; Reset the keyport (kinda)
  147.         out     (1),a
  148.         ld      a,0fdh          ; Enable the row with CLEAR
  149.         out     (1),a
  150.         in      a,(1)
  151.         cp      191             ; Check for CLEAR
  152.         jp      nz,MAIN         ; Exit if clear is pressed
  153.  
  154.  
  155.         call    CLRTSHD         ; Clear textshadow
  156.         call    GOHOME          ; Leave graphscreen and go to homescreen
  157.         call    BUFCLR          ; Clear the graphbuf
  158.         call    READKEY         ; Catch the clear press
  159.         call    HOMEUP          ; Place cursor at home
  160.         ret                     ; Exit program
  161.  
  162. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  163. ;│█████ Z80 ██████│   PROCEDURES   │█████████████████████│ movax │████████████│
  164. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  165.  
  166. ;▄████████████▀ SPRXOR ▀███████████████████████████████████████████████████████
  167. ;┌────────────────────────────────────────────────────────────────────────────┐
  168. ;│ Xor 8x8 sprite ■ a=x, e=y, hl=sprite address                               │
  169. ;└────────────────────────────────────────────────────────────────────────────┘
  170. SPRXOR:
  171.  
  172.         push    hl              ; Save sprite address
  173.  
  174. ;████   Calculate the address in graphbuf   ████
  175.  
  176.         ld      hl,0            ; Do y*12
  177.         ld      d,0
  178.         add     hl,de
  179.         add     hl,de
  180.         add     hl,de
  181.         add     hl,hl
  182.         add     hl,hl
  183.  
  184.         ld      d,0             ; Do x/8
  185.         ld      e,a
  186.         srl     e
  187.         srl     e
  188.         srl     e
  189.         add     hl,de
  190.  
  191.         ld      de,8e29h
  192.         add     hl,de           ; Add address to graphbuf
  193.  
  194.         ld      b,00000111b     ; Get the remainder of x/8
  195.         and     b
  196.         cp      0               ; Is this sprite aligned to 8*n,y?
  197.         jp      z,ALIGN
  198.  
  199.  
  200. ;████   Non aligned sprite blit starts here   ████
  201.  
  202.         pop     ix              ; ix->sprite
  203.         ld      d,a             ; d=how many bits to shift each line
  204.  
  205.         ld      e,8             ; Line loop
  206. LILOP:  ld      b,(ix+0)        ; Get sprite data
  207.  
  208.         ld      c,0             ; Shift loop
  209.         push    de
  210. SHLOP:  srl     b
  211.         rr      c
  212.         dec     d
  213.         jp      nz,SHLOP
  214.         pop     de
  215.  
  216.         ld      a,b             ; Write line to graphbuf
  217.         xor     (hl)
  218.         ld      (hl),a
  219.         inc     hl
  220.         ld      a,c
  221.         xor     (hl)
  222.         ld      (hl),a
  223.  
  224.         ld      bc,11           ; Calculate next line address
  225.         add     hl,bc
  226.         inc     ix              ; Inc spritepointer
  227.  
  228.         dec     e
  229.         jp      nz,LILOP        ; Next line
  230.  
  231.         jp      DONE1
  232.  
  233.  
  234. ;████   Aligned sprite blit starts here   ████
  235.  
  236. ALIGN:                          ; Blit an aligned sprite to graphbuf
  237.         pop     de              ; de->sprite
  238.         ld      b,8
  239. ALOP1:  ld      a,(de)
  240.         xor     (hl)
  241.         ld      (hl),a
  242.         inc     de
  243.         push    bc
  244.         ld      bc,12
  245.         add     hl,bc
  246.         pop     bc
  247.         djnz    ALOP1
  248.  
  249. DONE1:
  250.         ret
  251. ;▄████████████▄ SPRXOR ▄███████████████████████████████████████████████████████
  252.  
  253. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  254. ;│█████ Z80 ██████│     EQUALS     │█████████████████████│ movax │████████████│
  255. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  256.  
  257. WAITKEY .equ     4CFEh  ; Wait for a key and read
  258. BUFCLR    .equ     515Bh    ; Clear the graph backup
  259. BUFCOPY .equ     5164h    ; Copy the graph backup to the screen
  260. RINDOFF .equ     4795h    ; Turn off runindicator
  261. PRINTHL .equ     4709h    ; Print HL in dec. on the screen
  262. OP2TOP1 .equ     41C2h    ; Move OP2 to OP1
  263. CONVOP1 .equ     4EFCh    ; Convert fp value in OP1 to a 2 byte hex
  264. READKEY .equ     4A18h    ; Read key and place it in OP2 as a fp value
  265. GOHOME    .equ     47A1h    ; Go to home screen (finish gfx program)
  266. CLRTSHD .equ     4765h    ; Clear text shadow
  267. HOMEUP    .equ     4775h    ; Place cursor at home
  268. STRING    .equ     470Dh    ; Print 0 terminated string to screen (hl->string)
  269.  
  270. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  271. ;│█████ Z80 ██████│      DATA      │█████████████████████│ movax │████████████│
  272. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  273.  
  274. ALIEN   .db     00011000b
  275.         .db     01111110b
  276.         .db     11111111b
  277.         .db     10111101b
  278.         .db     10011001b
  279.         .db     11111111b
  280.         .db     01111110b
  281.         .db     00111100b
  282.  
  283. SPRCORD .db     40,0,48,0
  284.         .db     24,8,32,8,40,8,48,8,56,8,64,8
  285.         .db     16,16,24,16,32,16,40,16,48,16,56,16,64,16,72,16
  286.         .db     16,24,32,24,40,24,48,24,56,24,72,24
  287.         .db     16,32,40,32,48,32,72,32
  288.         .db     16,40,24,40,32,40,40,40,48,40,56,40,64,40,72,40
  289.         .db     24,48,32,48,40,48,48,48,56,48,64,48
  290.         .db     32,56,40,56,48,56,56,56
  291.  
  292. SPEED   .db     64
  293. KEY     .db     1
  294.  
  295. SPRDIR  .db     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  296.         .db     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  297.         .db     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  298.         .db     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  299.  
  300.  
  301. .end
  302. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  303. ;│█████ Z80 ██████│  Spr xor demo  │█████████████████████│ movax │████████████│
  304. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  305.