Skip to content

Commit 6dcd8c6

Browse files
committed
Added vdc samples with some refactor
1 parent 297424e commit 6dcd8c6

5 files changed

Lines changed: 189 additions & 46 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ retroProject {
1212
libDirs = ["..", ".ra/deps/c128lib"]
1313

1414
libFromGitHub "c128lib/common", "0.5.1"
15-
libFromGitHub "c128lib/chipset", "0.6.0-alpha"
15+
libFromGitHub "c128lib/chipset", "0.6.0-alpha2"
1616
}

disk-generator.asm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
[name="--- SAMPLES ---", type="usr"],
66
[name="---------------", type="usr"],
77
[name="CIA", type="prg", segments="Cia"],
8+
[name="VDC", type="prg", segments="Vdc"],
89
[name="VIC2", type="prg", segments="Vic2"],
910
}
1011

1112
#import "cia.asm"
13+
#import "vdc.asm"
1214
#import "vic2.asm"

keyboard-helper.asm

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#importonce
2+
3+
* = * "DetectKeyPressed"
4+
DetectKeyPressed: {
5+
sei
6+
lda #%11111111
7+
sta c128lib.Cia.CIA1_DATA_DIR_A
8+
lda #%00000000
9+
sta c128lib.Cia.CIA1_DATA_DIR_B
10+
11+
lda MaskOnPortA
12+
sta c128lib.Cia.CIA1_DATA_PORT_A
13+
lda c128lib.Cia.CIA1_DATA_PORT_B
14+
and MaskOnPortB
15+
beq Pressed
16+
lda #$00
17+
jmp !+
18+
Pressed:
19+
lda #$01
20+
!:
21+
cli
22+
rts
23+
24+
MaskOnPortA: .byte $00
25+
MaskOnPortB: .byte $00
26+
}
27+
28+
ReturnPressed: .byte $00
29+
30+
.macro IsReturnPressed() {
31+
lda #%11111110
32+
sta DetectKeyPressed.MaskOnPortA
33+
lda #%00000010
34+
sta DetectKeyPressed.MaskOnPortB
35+
jsr DetectKeyPressed
36+
sta ReturnPressed
37+
}
38+
39+
.macro IsReturnPressedAndReleased() {
40+
!:
41+
IsReturnPressed()
42+
beq !-
43+
!:
44+
jsr DetectKeyPressed
45+
bne !-
46+
}
47+
48+
#import "./chipset/lib/cia.asm"

vdc.asm

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#importonce
2+
.segmentdef Vdc [start=$1c01]
3+
.segment Vdc
4+
5+
c128lib_BasicUpstart128($1c10)
6+
7+
.namespace Vdc {
8+
* = $1c10 "Entry"
9+
Entry: {
10+
// Clean screen
11+
jsr c128lib.Kernal.CINT
12+
13+
c128lib_Go80()
14+
15+
// Set cursor on (0, 2)
16+
clc
17+
ldx #2
18+
ldy #0
19+
jsr c128lib.Kernal.PLOT
20+
21+
// Print string at current cursor position
22+
ldx #0
23+
!:
24+
lda SampleString, x
25+
jsr c128lib.Kernal.BSOUT
26+
inx
27+
cpx #SampleStringLength
28+
bne !-
29+
30+
IsReturnPressedAndReleased()
31+
32+
c128lib_SetBackgroundForegroundColor(c128lib.Vdc.VDC_DARK_CYAN, c128lib.Vdc.VDC_LIGHT_CYAN);
33+
34+
// Set cursor on (0, 5)
35+
clc
36+
ldx #5
37+
ldy #0
38+
jsr c128lib.Kernal.PLOT
39+
40+
// Print string at current cursor position
41+
ldx #0
42+
!:
43+
lda SampleString2, x
44+
jsr c128lib.Kernal.BSOUT
45+
inx
46+
cpx #SampleString2Length
47+
bne !-
48+
49+
IsReturnPressedAndReleased()
50+
51+
c128lib_SetBackgroundForegroundColor(c128lib.Vdc.VDC_DARK_RED, c128lib.Vdc.VDC_LIGHT_RED);
52+
53+
// Set cursor on (0, 8)
54+
clc
55+
ldx #8
56+
ldy #0
57+
jsr c128lib.Kernal.PLOT
58+
59+
// Print string at current cursor position
60+
ldx #0
61+
!:
62+
lda SampleString3, x
63+
jsr c128lib.Kernal.BSOUT
64+
inx
65+
cpx #SampleString3Length
66+
bne !-
67+
68+
IsReturnPressedAndReleased()
69+
70+
// Now let the user choose his favourite color
71+
UserSelect:
72+
clc
73+
ldx #11
74+
ldy #0
75+
jsr c128lib.Kernal.PLOT
76+
77+
// Print string at current cursor position
78+
ldx #0
79+
!:
80+
lda ColorString, x
81+
jsr c128lib.Kernal.BSOUT
82+
inx
83+
cpx #ColorStringLength
84+
bne !-
85+
86+
jsr c128lib.Kernal.GETIN
87+
cmp #48
88+
bcc UserSelect // Lower than '0'
89+
cmp #71
90+
bcs UserSelect // Greater than 'F'
91+
cmp #58
92+
bcc IsNumber
93+
cmp #65
94+
bcs IsLetter
95+
jmp UserSelect // If it's between ':' AND '-' restart
96+
97+
IsNumber:
98+
and #%00001111 // Number, take the lower nibble
99+
jmp ChooseColor
100+
101+
IsLetter:
102+
and #%00001111 // Letter, take the lower nibble
103+
clc
104+
adc #9 // Add 9 to convert to Hex
105+
106+
ChooseColor:
107+
sta background // Background
108+
eor #$FF
109+
and #%00001111
110+
sta foreground // Foreground is EOR(background) to make text readable
111+
c128lib_SetBackgroundForegroundColorWithVars(background, foreground)
112+
113+
jmp UserSelect // Back to user selection
114+
115+
background: .byte 0
116+
foreground: .byte 0
117+
}
118+
119+
}
120+
121+
ColorString: .text "SELECT COLOR (0 TO F): "
122+
.label ColorStringLength = 23;
123+
124+
SampleString: .text "LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT. MAURIS MOLLIS NEC MI VEL COMMODO."
125+
.label SampleStringLength = 90;
126+
127+
SampleString2: .text "UT EU LOREM URNA. PHASELLUS AC MAXIMUS LIBERO, VITAE FINIBUS NISL."
128+
.label SampleString2Length = 66;
129+
130+
SampleString3: .text "DUIS QUIS TEMPOR TELLUS. VIVAMUS MATTIS VESTIBULUM TORTOR ELEIFEND GRAVIDA."
131+
.label SampleString3Length = 75;
132+
133+
#import "keyboard-helper.asm"
134+
135+
#import "./common/lib/common-global.asm"
136+
#import "./chipset/lib/vdc-global.asm"

vic2.asm

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -71,51 +71,6 @@ CollisionIrq: {
7171
jmp $fa65
7272
}
7373

74-
* = * "DetectKeyPressed"
75-
DetectKeyPressed: {
76-
sei
77-
lda #%11111111
78-
sta c128lib.Cia.CIA1_DATA_DIR_A
79-
lda #%00000000
80-
sta c128lib.Cia.CIA1_DATA_DIR_B
81-
82-
lda MaskOnPortA
83-
sta c128lib.Cia.CIA1_DATA_PORT_A
84-
lda c128lib.Cia.CIA1_DATA_PORT_B
85-
and MaskOnPortB
86-
beq Pressed
87-
lda #$00
88-
jmp !+
89-
Pressed:
90-
lda #$01
91-
!:
92-
cli
93-
rts
94-
95-
MaskOnPortA: .byte $00
96-
MaskOnPortB: .byte $00
97-
}
98-
99-
ReturnPressed: .byte $00
100-
101-
.macro IsReturnPressed() {
102-
lda #%11111110
103-
sta DetectKeyPressed.MaskOnPortA
104-
lda #%00000010
105-
sta DetectKeyPressed.MaskOnPortB
106-
jsr DetectKeyPressed
107-
sta ReturnPressed
108-
}
109-
110-
.macro IsReturnPressedAndReleased() {
111-
!:
112-
IsReturnPressed()
113-
beq !-
114-
!:
115-
jsr DetectKeyPressed
116-
bne !-
117-
}
118-
11974
.macro SetupInterrupt() {
12075
sei
12176
lda #$7f
@@ -137,6 +92,8 @@ ReturnPressed: .byte $00
13792
cli
13893
}
13994

95+
#import "keyboard-helper.asm"
96+
14097
* = $2000 "Sprites"
14198
SPRITES:
14299
.import binary "./assets/sprites.bin"

0 commit comments

Comments
 (0)