gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/z80/putchar.s
1 .include "global.s"
2
3 .title "putchar"
4 .module putchar
5
6 .globl font_current, font_set, font_load_ibm
7 .globl .scroll_viewport
8
9 ; Structure offsets
10 sfont_handle_sizeof = 3
11 sfont_handle_font = 1
12 sfont_handle_first_tile = 0
13
14 ; Encoding types - lower 2 bits of font
15 FONT_256ENCODING = 0
16 FONT_128ENCODING = 1
17 FONT_NOENCODING = 2
18
19 .area _INITIALIZED
20 ; The current font
21 .curx::
22 .ds 1
23 .cury::
24 .ds 1
25
26 .area _INITIALIZER
27 .db #.SCREEN_X_OFS ; .curx
28 .db #.SCREEN_Y_OFS ; .cury
29
30 .area _HOME
31
32 _setchar::
33 _putchar::
34 pop hl
35 pop de
36 push de
37 push hl
38
39 ld a, e
40 cp #.CR
41 jr nz, 0$
42
43 ld a, #.SCREEN_X_OFS
44 ld (.curx), a
45 jp 2$
46 0$:
47 ld hl, (font_current+sfont_handle_font)
48 ld a, h
49 or l
50 jr nz, 6$
51
52 push de
53 call font_load_ibm
54 ld a, h
55 or l
56 ret z
57 call font_set
58 pop de
59 ld hl, (font_current+sfont_handle_font)
60 6$:
61 ld a, (hl)
62 and #3
63 cp #FONT_NOENCODING
64 jr z, 4$
65 inc hl
66 inc hl
67 ld d, #0
68 add hl, de
69 ld e, (hl)
70 4$:
71 ld a, (font_current)
72 add a, e
73 ld e, a
74
75 DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT
76
77 ld a, (.cury)
78 ld l, a
79 ld h, #0
80 add hl, hl
81 add hl, hl
82 add hl, hl
83 add hl, hl
84 add hl, hl
85 add hl, hl
86 ld a, (.curx)
87 add a
88 add l
89 ld l, a
90 adc h
91 sub l
92 ld h, a
93
94 ld a, (_shadow_VDP_R2)
95 rlca
96 rlca
97 and #0b01111000
98 ld b, a
99 ld c, #0
100 add hl, bc
101
102 WRITE_VDP_CMD_HL
103
104 ld a, e
105 out (.VDP_DATA), a
106 VDP_DELAY
107 xor a
108 out (.VDP_DATA), a
109
110 ENABLE_VBLANK_COPY ; switch ON copy shadow SAT
111
112 ld a, (.curx)
113 inc a
114 cp #(.SCREEN_X_OFS + .SCREEN_WIDTH)
115 jr c, 5$
116 ld a, #.SCREEN_X_OFS
117 5$:
118 ld (.curx), a
119 ret nz
120 2$:
121 ld a, (.cury)
122 inc a
123 cp #(.SCREEN_Y_OFS + .SCREEN_HEIGHT)
124 jr c, 3$
125 ld a, #(.SCREEN_Y_OFS + .SCREEN_HEIGHT - 1)
126 ld (.cury), a
127
128 call .scroll_viewport
129 ret
130 3$:
131 ld (.cury), a
132 ret
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.