Advertisement
Guest User

Printputc v2.1

a guest
Apr 29th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; @brief Writes a character to the screen at the current coordinates
  2. ; @param c Character to print
  3. ; @destroy a
  4. ; @destroy de
  5. ; @destroy hl
  6. Printputc:
  7.     ; This will put PrintY into d and PrintX into e
  8.     ld hl, PrintX
  9.     ld a, [hli]
  10.     ld e, a
  11.     ld a, [hl]
  12.     ld d, a
  13.  
  14.     ld h, 0     ;
  15.     ld l, d     ;
  16.                 ;
  17. rept 5          ;
  18.     add hl, hl  ; Multiply y coordinate by 32 to get visible screen space location
  19. endr
  20.  
  21.     ; Add map base offset
  22.     ld a, h
  23.     add $98
  24.     ld h, a
  25.  
  26.     ; Add x coordinate offset
  27.     ld a, e
  28.     add l
  29.     ld l, a
  30.  
  31.     ld [hl], c
  32.  
  33.     ; Update coordinates
  34.     inc e
  35.  
  36. .checkX
  37.     ld a, PrintMaxX
  38.     cp a, e
  39.     jr nc, .checkY
  40.     ld e, 0
  41.     inc d
  42. .checkY
  43.     ld a, PrintMaxY
  44.     cp a, d
  45.     jr nc, .storeCoords
  46.     ld d, 0
  47. .storeCoords
  48.     ld a, d
  49.     ld [PrintY], a
  50.     ld a, e
  51.     ld [PrintX], a
  52.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement