Skip to content

Commit 2d5abf2

Browse files
committed
Vdc complete
1 parent 09d370a commit 2d5abf2

2 files changed

Lines changed: 241 additions & 11 deletions

File tree

lib/vdc-global.asm

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/**
2+
* @file vdc-global.asm
3+
* @brief Vdc module
4+
* @details Simple macros for Vdc.
5+
*
6+
* @author Raffaele Intorcia raffaele.intorcia@gmail.com
7+
*
8+
* @copyright MIT License
9+
* Copyright (c) 2024 c128lib - https://github.com/c128lib
10+
*
11+
* Permission is hereby granted, free of charge, to any person obtaining a copy
12+
* of this software and associated documentation files (the "Software"), to deal
13+
* in the Software without restriction, including without limitation the rights
14+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
* copies of the Software, and to permit persons to whom the Software is
16+
* furnished to do so, subject to the following conditions:
17+
*
18+
* The above copyright notice and this permission notice shall be included in all
19+
* copies or substantial portions of the Software.
20+
*
21+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27+
* SOFTWARE.
28+
*
29+
* @date 2024
30+
*/
31+
32+
#importonce
33+
34+
#import "vdc.asm"
35+
36+
.filenamespace c128lib
37+
38+
/**
39+
* @brief Go to 40 columns mode
40+
*
41+
* @remark Register .A will be modified.
42+
* @remark Flags N and Z will be affected.
43+
*
44+
* @since 1.1.0
45+
*/
46+
.macro c128lib_Go40() { Go40() }
47+
48+
/**
49+
* @brief Go to 80 columns mode
50+
*
51+
* @remark Register .A will be modified.
52+
* @remark Flags N and Z will be affected.
53+
*
54+
* @since 1.1.0
55+
*/
56+
.macro c128lib_Go80() { Go80() }
57+
58+
/**
59+
* @brief Set background and foreground color, also disable bit 6 of
60+
* HORIZONTAL_SMOOTH_SCROLLING register
61+
*
62+
* @param[in] background Background color
63+
* @param[in] foreground Foreground color
64+
*
65+
* @remark Register .A and .X will be modified.
66+
* @remark Flags N, Z and O will be affected.
67+
*
68+
* @since 1.1.0
69+
*/
70+
.macro c128lib_SetBackgroundForegroundColor(background, foreground) { SetBackgroundForegroundColor(background, foreground) }
71+
72+
/**
73+
* @brief Set background and foreground color, also disable bit 6 of
74+
* HORIZONTAL_SMOOTH_SCROLLING register. Use vars instead of labels.
75+
* Warning: high nibble of background must be 0, it's up to developer
76+
* to check this.
77+
*
78+
* @param[in] background Background color address
79+
* @param[in] foreground Foreground color address
80+
*
81+
* @remark Register .A and .X will be modified.
82+
* @remark Flags N, Z, C and O will be affected.
83+
*
84+
* @since 1.1.0
85+
*/
86+
.macro c128lib_SetBackgroundForegroundColorWithVars(background, foreground) { SetBackgroundForegroundColorWithVars(background, foreground) }
87+
88+
/**
89+
* @brief Read from Vdc internal memory and write it to Vic screen memory by
90+
* using coordinates.
91+
*
92+
* @param[in] xPos X coord on Vdc screen
93+
* @param[in] yPos Y coord on Vdc screen
94+
* @param[in] destination Vic screen memory absolute address
95+
* @param[in] qty Number of byte to copy
96+
*
97+
* @remark Register .A and .X will be modified.
98+
* @remark Flags N, Z and O will be affected.
99+
*
100+
* @since 1.1.0
101+
*/
102+
.macro c128lib_ReadFromVdcMemoryByCoordinates(xPos, yPos, destination, qty) { ReadFromVdcMemoryByCoordinates(xPos, yPos, destination, qty) }
103+
104+
/**
105+
* @brief Read from Vdc internal memory and write it to Vic screen memory by
106+
* using source address.
107+
*
108+
* @param[in] source Vdc memory absolute address
109+
* @param[in] destination Vic screen memory absolute address
110+
* @param[in] qty Number of byte to copy
111+
*
112+
* @remark Register .A, .X and .Y will be modified.
113+
* @remark Flags N, Z and C will be affected.
114+
*
115+
* @since 1.1.0
116+
*/
117+
.macro c128lib_ReadFromVdcMemoryByAddress(source, destination, qty) { ReadFromVdcMemoryByAddress(source, destination, qty) }
118+
119+
/**
120+
* @brief Read from Vic screen memory and write it to Vdc internal memory by
121+
* using coordinates.
122+
*
123+
* @param[in] xPos X coord on Vic screen
124+
* @param[in] yPos Y coord on Vic screen
125+
* @param[in] destination Vdc internal memory absolute address
126+
* @param[in] qty Number of byte to copy
127+
*
128+
* @remark Register .A, .X and .Y will be modified.
129+
* @remark Flags N, Z and C will be affected.
130+
*
131+
* @since 1.1.0
132+
*/
133+
.macro c128lib_WriteToVdcMemoryByCoordinates(source, xPos, yPos, qty) { WriteToVdcMemoryByCoordinates(source, xPos, yPos, qty) }
134+
135+
/**
136+
* @brief Read from Vic screen memory and write it to Vdc internal memory by
137+
* using coordinates.
138+
*
139+
* @param[in] source Vdc memory absolute address
140+
* @param[in] destination Vic screen memory absolute address
141+
* @param[in] qty Number of byte to copy
142+
*
143+
* @remark Register .A, .X and .Y will be modified.
144+
* @remark Flags N, Z and C will be affected.
145+
*
146+
* @since 1.1.0
147+
*/
148+
.macro c128lib_WriteToVdcMemoryByAddress(source, destination, qty) { WriteToVdcMemoryByAddress(source, destination, qty) }
149+
150+
/**
151+
* @brief Returns the address start of Vdc display memory data. This
152+
* is stored in Vdc register SCREEN_MEMORY_STARTING_HIGH_ADDRESS and
153+
* SCREEN_MEMORY_STARTING_LOW_ADDRESS.
154+
* The 16-bit value is stored in $FB and $FC.
155+
*
156+
* @remark Register .A and .X will be modified.
157+
* @remark Flags N, Z and O will be affected.
158+
*
159+
* @since 1.1.0
160+
*/
161+
.macro c128lib_GetVdcDisplayStart() { GetVdcDisplayStart() }
162+
163+
/**
164+
* @brief Set the pointer to the RAM area that is to be updated.
165+
* The update pointer is stored in Vdc register CURRENT_MEMORY_HIGH_ADDRESS
166+
* and CURRENT_MEMORY_LOW_ADDRESS.
167+
*
168+
* @param[in] address Address of update area
169+
*
170+
* @remark Register .A and .X will be modified.
171+
* @remark Flags N, Z and O will be affected.
172+
*
173+
* @since 1.1.0
174+
*/
175+
.macro c128lib_SetVdcUpdateAddress(address) { SetVdcUpdateAddress(address) }
176+
177+
/**
178+
* @brief Write a value into Vdc register without using kernal
179+
* routine instead of pure instruction. It needs register
180+
* number in X and value to write in A.
181+
* It costs 11 bytes and 14 cycles.
182+
*
183+
* @pre Register .X must be filled with internal Vdc register
184+
* to write on.
185+
* @pre Register .A must be filled with the value that will be
186+
* written to internal Vdc register.
187+
* @remark Flags N, Z and O will be affected.
188+
*
189+
* @since 1.1.0
190+
*/
191+
.macro c128lib_WriteVdc() { WriteVdc() }
192+
193+
/**
194+
* @brief Read a value from Vdc register without using kernal
195+
* routine instead of pure instruction. It needs register
196+
* number in X and value is written in A.
197+
* It costs 11 bytes and 14 cycles.
198+
*
199+
* @pre Register .X must be filled with internal Vdc register
200+
* to read from.
201+
* @remark Register .A will be modified.
202+
* @remark Flags N, Z and O will be affected.
203+
* @post Register .A will contain the value read from internal
204+
* Vdc register.
205+
*
206+
* @since 1.1.0
207+
*/
208+
.macro c128lib_ReadVdc() { ReadVdc() }

lib/vdc.asm

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ InitText: {
328328
* @param[in] background Background color
329329
* @param[in] foreground Foreground color
330330
*
331+
* @remark Register .A and .X will be modified.
332+
* @remark Flags N, Z and O will be affected.
333+
*
331334
* @note Use c128lib_SetBackgroundForegroundColor in vdc-global.asm
332335
*
333336
* @since 1.1.0
@@ -365,6 +368,9 @@ InitText: {
365368
* @param[in] background Background color address
366369
* @param[in] foreground Foreground color address
367370
*
371+
* @remark Register .A and .X will be modified.
372+
* @remark Flags N, Z, C and O will be affected.
373+
*
368374
* @note Use c128lib_SetBackgroundForegroundColorWithVars in vdc-global.asm
369375
*
370376
* @since 1.1.0
@@ -409,6 +415,9 @@ InitText: {
409415
* @param[in] destination Vic screen memory absolute address
410416
* @param[in] qty Number of byte to copy
411417
*
418+
* @remark Register .A and .X will be modified.
419+
* @remark Flags N, Z and O will be affected.
420+
*
412421
* @note Use c128lib_ReadFromVdcMemoryByCoordinates in vdc-global.asm
413422
*
414423
* @since 1.1.0
@@ -465,6 +474,9 @@ InitText: {
465474
* @param[in] destination Vic screen memory absolute address
466475
* @param[in] qty Number of byte to copy
467476
*
477+
* @remark Register .A, .X and .Y will be modified.
478+
* @remark Flags N, Z and C will be affected.
479+
*
468480
* @note Use c128lib_ReadFromVdcMemoryByAddress in vdc-global.asm
469481
*
470482
* @since 1.1.0
@@ -474,14 +486,14 @@ InitText: {
474486
.errorif (qty > 255), "qty must be lower than 256"
475487
ldx #$12
476488
lda #>source
477-
jsr c128lib.ScreenEditor.WRITEREG
489+
jsr ScreenEditor.WRITEREG
478490
lda #<source
479491
inx
480-
jsr c128lib.ScreenEditor.WRITEREG
492+
jsr ScreenEditor.WRITEREG
481493

482494
ldy #0
483495
CopyLoop:
484-
jsr c128lib.ScreenEditor.WRITE80
496+
jsr ScreenEditor.WRITE80
485497
sta destination, y
486498
iny
487499
cpy #qty
@@ -509,6 +521,9 @@ InitText: {
509521
* @param[in] destination Vdc internal memory absolute address
510522
* @param[in] qty Number of byte to copy
511523
*
524+
* @remark Register .A, .X and .Y will be modified.
525+
* @remark Flags N, Z and C will be affected.
526+
*
512527
* @note Use c128lib_WriteToVdcMemoryByCoordinates in vdc-global.asm
513528
*
514529
* @since 1.1.0
@@ -522,15 +537,15 @@ InitText: {
522537
.if (xPos != -1 && yPos != -1) {
523538
ldx #$12
524539
lda #>getTextOffset80Col(xPos, yPos)
525-
jsr c128lib.ScreenEditor.WRITEREG
540+
jsr ScreenEditor.WRITEREG
526541
lda #<getTextOffset80Col(xPos, yPos)
527542
inx
528-
jsr c128lib.ScreenEditor.WRITEREG
543+
jsr ScreenEditor.WRITEREG
529544
}
530545
ldy #0
531546
CopyLoop:
532547
lda source, y
533-
jsr c128lib.ScreenEditor.WRITE80
548+
jsr ScreenEditor.WRITE80
534549
iny
535550
cpy #qty
536551
bne CopyLoop
@@ -565,6 +580,9 @@ InitText: {
565580
* @param[in] destination Vic screen memory absolute address
566581
* @param[in] qty Number of byte to copy
567582
*
583+
* @remark Register .A, .X and .Y will be modified.
584+
* @remark Flags N, Z and C will be affected.
585+
*
568586
* @note Use c128lib_WriteToVdcMemoryByAddress in vdc-global.asm
569587
*
570588
* @since 1.1.0
@@ -574,15 +592,15 @@ InitText: {
574592
.errorif (qty > 255), "qty must be lower than 256"
575593
ldx #$12
576594
lda #>destination
577-
jsr c128lib.ScreenEditor.WRITEREG
595+
jsr ScreenEditor.WRITEREG
578596
lda #<destination
579597
inx
580-
jsr c128lib.ScreenEditor.WRITEREG
598+
jsr ScreenEditor.WRITEREG
581599

582600
ldy #0
583601
CopyLoop:
584602
lda source, y
585-
jsr c128lib.ScreenEditor.WRITE80
603+
jsr ScreenEditor.WRITE80
586604
iny
587605
cpy #qty
588606
bne CopyLoop
@@ -608,8 +626,6 @@ InitText: {
608626
* @param[in] yPos Y coord on Vdc screen
609627
* @return Memory offset of Vdc specified coordinate
610628
*
611-
* @note Use c128lib_WriteToVdcMemoryByAddress in vdc-global.asm
612-
*
613629
* @since 1.1.0
614630
*/
615631
.function getTextOffset80Col(xPos, yPos) {
@@ -627,6 +643,9 @@ InitText: {
627643
* SCREEN_MEMORY_STARTING_LOW_ADDRESS.
628644
* The 16-bit value is stored in $FB and $FC.
629645
*
646+
* @remark Register .A and .X will be modified.
647+
* @remark Flags N, Z and O will be affected.
648+
*
630649
* @note Use c128lib_GetVdcDisplayStart in vdc-global.asm
631650
*
632651
* @since 1.1.0
@@ -648,6 +667,9 @@ InitText: {
648667
*
649668
* @param[in] address Address of update area
650669
*
670+
* @remark Register .A and .X will be modified.
671+
* @remark Flags N, Z and O will be affected.
672+
*
651673
* @note Use c128lib_SetVdcUpdateAddress in vdc-global.asm
652674
*
653675
* @since 1.1.0

0 commit comments

Comments
 (0)