Skip to content

Commit

Permalink
Merge pull request #8 from c128lib/intoinside/issue4
Browse files Browse the repository at this point in the history
Intoinside/issue4
  • Loading branch information
intoinside authored Oct 27, 2022
2 parents a457520 + 83a4105 commit fd9a94d
Showing 1 changed file with 76 additions and 20 deletions.
96 changes: 76 additions & 20 deletions lib/vdc.asm
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#import "common/lib/common.asm"

/*
* Set of variables, functions and macros
* for handling VDC graphic processor.
*
* Requires KickAssembler v5.x
* (c) 2022 Raffaele Intorcia
*/
*
* Ref: https://www.cubic.org/~doj/c64/mapping128.pdf
*/
#importonce
.filenamespace c128lib

Expand All @@ -15,15 +14,56 @@
.label MODE = $d7

/*
* VDC registers
*/
VDC registers
*/
.label VDCADR = $d600 // VDC address/status register
.label VDCDAT = $d601 // VDC data register

/*
VDC internal registers
*/
.label TOTALE_NUMBER_OF_HORIZONTAL_CHARACTER_POSITIONS = $00
.label NUMBER_OF_VISIBILE_HORIZONTAL_CHARACTER_POSITIONS = $01
.label HORIZONTAL_SYNC_POSITION = $02
.label HORIZONTAL_VERTICAL_SYNC_WIDTH = $03
.label NUMBER_SCREEN_ROWS = $04
.label VERTICAL_FINE_ADJUSTMENT = $05
.label VISIBLE_SCREEN_ROWS = $06
.label VERTICAL_SYNC_POSITION = $07
.label INTERLACE_MODE_CONTRO_POSITION = $08
.label SCANLINES_PER_CHARACTER = $09
.label CURSOR_MODE_CONTROL = $0A
.label ENDING_SCAN_LINE = $0B
.label SCREEN_MEMORY_STARTING_HIGH_ADDRESS = $0C
.label SCREEN_MEMORY_STARTING_LOW_ADDRESS = $0D
.label CURSOR_POSITION_HIGH_ADDRESS = $0E
.label CURSOR_POSITION_LOW_ADDRESS = $0F
.label LIGHT_PEN_VERTICAL_POSITION = $10
.label LIGHT_PEN_HORIZONTAL_POSITION = $11
.label CURRENT_MEMORY_HIGH_ADDRESS = $12
.label CURRENT_MEMORY_LOW_ADDRESS = $13
.label ATTRIBUTE_MEMORY_HIGH_ADDRESS = $14
.label ATTRIBUTE_MEMORY_LOW_ADDRESS = $15
.label CHARACTER_HORIZONTAL_SIZE_CONTROL = $16
.label CHARACTER_VERTICAL_SIZE_CONTROL = $17
.label VERTICAL_SMOOTH_SCROLLING = $18
.label HORIZONTAL_SMOOTH_SCROLLING = $19
.label FOREGROUND_BACKGROUND_COLOR = $1A
.label ADDRESS_INCREMENT_PER_ROW = $1B
.label CHARACTER_SET_ADDRESS = $1C
.label UNDERLINE_SCAN_LINE_POSITION = $1D
.label NUMBER_OF_BYTES_FOR_BLOCK_WRITE_OR_COPY = $1E
.label MEMORY_READ_WRITE = $1F
.label BLOCK_COPY_SOURCE_HIGH_ADDRESS = $20
.label BLOCK_COPY_SOURCE_LOW_ADDRESS = $21
.label BEGINNING_POSITION_FOR_HORIZONTAL_BLANKING = $22
.label ENDING_POSITION_FOR_HORIZONTAL_BLANKING = $23
.label NUMBER_OF_MEMORY_REFRESH_CYCLER_PER_SCANLINE = $24

.label SWAPPER = $ff5f // switch between 40 or 80 colums

/*
Go to 80 columns mode
Go to 80 columns mode
*/
.macro Go80() {
lda MODE // are we in 80 columns mode?
Expand All @@ -33,14 +73,24 @@ Go to 80 columns mode
}

/*
Returns the address start of VDC display memory data. This
is stored in VDC register 12 and 13.
The 16-bit value is stored in $FB and $FC.
Go to 40 columns mode
*/
.macro Go40() {
lda MODE // are we in 40 columns mode?
bpl !+ // bit 7 unset? then yes
jsr SWAPPER // swap mode to 40 columns
!:
}

Syntax: GetVDCDisplayStart()
/*
Returns the address start of VDC display memory data. This
is stored in VDC register 12 and 13.
The 16-bit value is stored in $FB and $FC.

Syntax: GetVDCDisplayStart()
*/
.macro GetVDCDisplayStart() {
ldx #12
ldx #SCREEN_MEMORY_STARTING_HIGH_ADDRESS
ReadVDC()

sta $fb
Expand All @@ -50,16 +100,16 @@ Syntax: GetVDCDisplayStart()
}

/*
Set the pointer to the RAM area that is to be updated.
The update pointer is stored in VDC register 18 and 19.
Set the pointer to the RAM area that is to be updated.
The update pointer is stored in VDC register 18 and 19.

Syntax: SetVDCUpdateAddress($1200)
Syntax: SetVDCUpdateAddress($1200)

This will point register 18 and 19 to $1200. This area
can then be written to using WriteVDCRAM()
This will point register 18 and 19 to $1200. This area
can then be written to using WriteVDCRAM()
*/
.macro SetVDCUpdateAddress(address) {
ldx #18
ldx #CURRENT_MEMORY_HIGH_ADDRESS
lda #>address
WriteVDC();

Expand All @@ -73,9 +123,9 @@ can then be written to using WriteVDCRAM()
}

/*
Translates between VIC and VDC color codes.
Translates between VIC and VDC color codes.

Syntax: GetVDCColor(0)
Syntax: GetVDCColor(0)
*/
.macro GetVDCColor(viccolor) {
ldx #viccolor
Expand All @@ -91,10 +141,16 @@ Syntax: GetVDCColor(0)
bpl !-
sta VDCDAT
}
.assert "WriteVDC()", { WriteVDC() }, {
stx $d600; bit $d600; bpl *-3; sta $d601
}

.macro ReadVDC() {
stx VDCADR
!: bit VDCADR
bpl !-
lda VDCDAT
}
.assert "ReadVDC()", { ReadVDC() }, {
stx $d600; bit $d600; bpl *-3; lda $d601
}

0 comments on commit fd9a94d

Please sign in to comment.