From 22d4b0d497e72779bcc328987fc69bca4a402178 Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Thu, 8 Mar 2018 16:06:33 -0800 Subject: [PATCH 1/5] Improved tv timing detection for the c64. --- asminc/get_tv.inc | 2 ++ include/cbm.h | 4 +++- libsrc/c64/get_tv.s | 43 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/asminc/get_tv.inc b/asminc/get_tv.inc index 47e0d9c2a..2d4b5b253 100644 --- a/asminc/get_tv.inc +++ b/asminc/get_tv.inc @@ -11,6 +11,8 @@ .enum TV NTSC PAL + NTSC_OLD + PAL_N OTHER .endenum diff --git a/include/cbm.h b/include/cbm.h index 1395f700f..b121050af 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -150,7 +150,9 @@ struct cbm_dirent { #define TV_NTSC 0 #define TV_PAL 1 -#define TV_OTHER 2 +#define TV_NTSC_OLD 2 +#define TV_PAL_N 3 +#define TV_OTHER 4 unsigned char get_tv (void); /* Return the video mode the machine is using. */ diff --git a/libsrc/c64/get_tv.s b/libsrc/c64/get_tv.s index 4f46b8d64..8c73f6fa4 100644 --- a/libsrc/c64/get_tv.s +++ b/libsrc/c64/get_tv.s @@ -3,6 +3,11 @@ ; ; unsigned char get_tv (void); ; /* Return the video mode the machine is using */ +; +; Changed to actually detect the mode instead of using a flag +; Marco van den Heuvel, 2018-03-08 +; +; The detection goes wrong on accelerated machines for now. ; .include "c64.inc" @@ -13,8 +18,42 @@ .proc _get_tv - lda PALFLAG - ldx #0 + php + sei +timing_loop_0: + lda VIC_HLINE +timing_loop_1: + cmp VIC_HLINE + beq timing_loop_1 + bmi timing_loop_0 + and #$03 + cmp #$01 + bne check_ntsc + lda #TV::NTSC_OLD ; NTSC OLD constant + bne detected +check_ntsc: + cmp #$03 + bcc ntsc + +; check for PAL and PAL-N + + ldx #$00 + lda #$10 +timing_loop_2: + inx + cmp VIC_HLINE + bne timing_loop_2 + lda #TV::PAL ; PAL constant + cpx #$70 + bcc detected + lda #TV::PAL_N ; PAL-N constant +detected: + ldx #$00 + plp rts +ntsc: + lda #TV::NTSC ; NTSC constant + beq detected + .endproc From 0eb1eb625fac71db5c0bfd79e6847a29be867d22 Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Fri, 9 Mar 2018 10:46:02 -0800 Subject: [PATCH 2/5] Undo my previous commit. --- asminc/get_tv.inc | 2 -- include/cbm.h | 4 +--- libsrc/c64/get_tv.s | 43 ++----------------------------------------- 3 files changed, 3 insertions(+), 46 deletions(-) diff --git a/asminc/get_tv.inc b/asminc/get_tv.inc index 2d4b5b253..47e0d9c2a 100644 --- a/asminc/get_tv.inc +++ b/asminc/get_tv.inc @@ -11,8 +11,6 @@ .enum TV NTSC PAL - NTSC_OLD - PAL_N OTHER .endenum diff --git a/include/cbm.h b/include/cbm.h index b121050af..1395f700f 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -150,9 +150,7 @@ struct cbm_dirent { #define TV_NTSC 0 #define TV_PAL 1 -#define TV_NTSC_OLD 2 -#define TV_PAL_N 3 -#define TV_OTHER 4 +#define TV_OTHER 2 unsigned char get_tv (void); /* Return the video mode the machine is using. */ diff --git a/libsrc/c64/get_tv.s b/libsrc/c64/get_tv.s index 8c73f6fa4..4f46b8d64 100644 --- a/libsrc/c64/get_tv.s +++ b/libsrc/c64/get_tv.s @@ -3,11 +3,6 @@ ; ; unsigned char get_tv (void); ; /* Return the video mode the machine is using */ -; -; Changed to actually detect the mode instead of using a flag -; Marco van den Heuvel, 2018-03-08 -; -; The detection goes wrong on accelerated machines for now. ; .include "c64.inc" @@ -18,42 +13,8 @@ .proc _get_tv - php - sei -timing_loop_0: - lda VIC_HLINE -timing_loop_1: - cmp VIC_HLINE - beq timing_loop_1 - bmi timing_loop_0 - and #$03 - cmp #$01 - bne check_ntsc - lda #TV::NTSC_OLD ; NTSC OLD constant - bne detected -check_ntsc: - cmp #$03 - bcc ntsc - -; check for PAL and PAL-N - - ldx #$00 - lda #$10 -timing_loop_2: - inx - cmp VIC_HLINE - bne timing_loop_2 - lda #TV::PAL ; PAL constant - cpx #$70 - bcc detected - lda #TV::PAL_N ; PAL-N constant -detected: - ldx #$00 - plp + lda PALFLAG + ldx #0 rts -ntsc: - lda #TV::NTSC ; NTSC constant - beq detected - .endproc From 0c7496f08b8a450dc5e963602c72b737687ba544 Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Fri, 16 Mar 2018 14:23:52 -0700 Subject: [PATCH 3/5] Added vic20 - ram emd. --- include/vic20.h | 2 +- libsrc/vic20/emd/vic20-rama.s | 258 ++++++++++++++++++++++++++++++++++ libsrc/vic20/libref.s | 2 + 3 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 libsrc/vic20/emd/vic20-rama.s diff --git a/include/vic20.h b/include/vic20.h index c6ad9632d..1e8c4ceb5 100644 --- a/include/vic20.h +++ b/include/vic20.h @@ -105,7 +105,7 @@ extern void vic20_ptvjoy_joy[]; extern void vic20_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ - +extern void vic20_rama_emd[]; /* End of vic20.h */ #endif diff --git a/libsrc/vic20/emd/vic20-rama.s b/libsrc/vic20/emd/vic20-rama.s new file mode 100644 index 000000000..a48959c13 --- /dev/null +++ b/libsrc/vic20/emd/vic20-rama.s @@ -0,0 +1,258 @@ +; +; Extended memory driver for the VIC20 $A000-$BFFF RAM. Driver works without +; problems when statically linked. +; +; Marco van den Heuvel, 2018-03-16 +; + + .include "zeropage.inc" + + .include "em-kernel.inc" + .include "em-error.inc" + + + .macpack generic + .macpack module + + +; ------------------------------------------------------------------------ +; Header. Includes jump table + + module_header _vic20_rama_emd + +; Driver signature + + .byte $65, $6d, $64 ; "emd" + .byte EMD_API_VERSION ; EM API version number + +; Library reference + + .addr $0000 + +; Jump table + + .addr INSTALL + .addr UNINSTALL + .addr PAGECOUNT + .addr MAP + .addr USE + .addr COMMIT + .addr COPYFROM + .addr COPYTO + +; ------------------------------------------------------------------------ +; Constants + +BASE = $A000 +PAGES = ($C000 - BASE) / 256 + +; ------------------------------------------------------------------------ +; Data. + +.bss +curpage: .res 1 ; Current page number +window: .res 256 ; Memory "window" + +.code + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present and determine the amount of +; memory available. +; Must return an EM_ERR_xx code in a/x. +; + +INSTALL: + lda $A000 ; see what is at address $A000 + inc $A000 ; see if it can be changed + cmp $A000 ; did it stick ? + beq nomem + dec $A000 + + ldx #$FF + stx curpage ; Invalidate the current page + inx ; X = 0 + txa ; A = X = EM_ERR_OK + rts + +nomem: ldx #>EM_ERR_NO_DEVICE + lda #PAGES + rts + +; ------------------------------------------------------------------------ +; MAP: Map the page in a/x into memory and return a pointer to the page in +; a/x. The contents of the currently mapped page (if any) may be discarded +; by the driver. +; + +MAP: sta curpage ; Remember the new page + + clc + adc #>BASE + sta ptr1+1 + ldy #$00 + sty ptr1 + + lda #window + sta ptr2+1 + +; Transfer one page + + jsr transfer ; Transfer one page + +; Return the memory window + + lda #window ; Return the window address + rts + +; ------------------------------------------------------------------------ +; USE: Tell the driver that the window is now associated with a given page. + +USE: sta curpage ; Remember the page + lda #window ; Return the window + rts + +; ------------------------------------------------------------------------ +; COMMIT: Commit changes in the memory window to extended storage. + +COMMIT: lda curpage ; Get the current page + bmi done ; Jump if no page mapped + + clc + adc #>BASE + sta ptr2+1 + ldy #$00 + sty ptr2 + + lda #window + sta ptr1+1 + +; Transfer one page. Y must be zero on entry + +transfer: + +; Unroll the following loop + +loop: .repeat 8 + lda (ptr1),y + sta (ptr2),y + iny + .endrepeat + + bne loop + +; Done + +done: rts + +; ------------------------------------------------------------------------ +; COPYFROM: Copy from extended into linear memory. A pointer to a structure +; describing the request is passed in a/x. +; The function must not return anything. +; + +COPYFROM: + sta ptr3 + stx ptr3+1 ; Save the passed em_copy pointer + + ldy #EM_COPY::OFFS + lda (ptr3),y + sta ptr1 + ldy #EM_COPY::PAGE + lda (ptr3),y + clc + adc #>BASE + sta ptr1+1 ; From + + ldy #EM_COPY::BUF + lda (ptr3),y + sta ptr2 + iny + lda (ptr3),y + sta ptr2+1 ; To + +common: ldy #EM_COPY::COUNT+1 + lda (ptr3),y ; Get number of pages + beq @L2 ; Skip if no full pages + sta tmp1 + +; Copy full pages allowing interrupts after each page copied + + ldy #$00 +@L1: jsr transfer + inc ptr1+1 + inc ptr2+1 + dec tmp1 + bne @L1 + +; Copy the remainder of the page + +@L2: ldy #EM_COPY::COUNT + lda (ptr3),y ; Get bytes in last page + beq @L4 + tax + +; Transfer the bytes in the last page + + ldy #$00 +@L3: lda (ptr1),y + sta (ptr2),y + iny + dex + bne @L3 + +; Done + +@L4: rts + +; ------------------------------------------------------------------------ +; COPYTO: Copy from linear into extended memory. A pointer to a structure +; describing the request is passed in a/x. +; The function must not return anything. +; + +COPYTO: sta ptr3 + stx ptr3+1 ; Save the passed em_copy pointer + + ldy #EM_COPY::OFFS + lda (ptr3),y + sta ptr2 + ldy #EM_COPY::PAGE + lda (ptr3),y + clc + adc #>BASE + sta ptr2+1 ; To + + ldy #EM_COPY::BUF + lda (ptr3),y + sta ptr1 + iny + lda (ptr3),y + sta ptr1+1 ; From + + jmp common + diff --git a/libsrc/vic20/libref.s b/libsrc/vic20/libref.s index e4afa7eb1..468c540f1 100644 --- a/libsrc/vic20/libref.s +++ b/libsrc/vic20/libref.s @@ -3,6 +3,8 @@ ; .export joy_libref + .export em_libref .import _exit joy_libref := _exit +em_libref := _exit From 12f72a5ed70ec45d5e037089a4eea6d08d037dee Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Sat, 17 Mar 2018 09:25:42 -0700 Subject: [PATCH 4/5] Added vic20 emd documentation. --- doc/vic20.sgml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/vic20.sgml b/doc/vic20.sgml index 26a4aa558..9f96cd388 100644 --- a/doc/vic20.sgml +++ b/doc/vic20.sgml @@ -147,7 +147,9 @@ No graphics drivers are currently available for the VIC20. Extended memory drivers

-No extended memory drivers are currently available for the VIC20. + + A driver for any RAM at $A000-$BFFF. Supports 32 256 byte pages. + Written and contributed by Marco van den Heuvel. Joystick drivers

From 4fdc2d7209612ffe94df4c4bf5acca52122e6fbe Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Sun, 18 Mar 2018 12:06:43 -0700 Subject: [PATCH 5/5] Fix documentation building issue. --- doc/vic20.sgml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/vic20.sgml b/doc/vic20.sgml index 9f96cd388..13f2a5cc8 100644 --- a/doc/vic20.sgml +++ b/doc/vic20.sgml @@ -147,10 +147,14 @@ No graphics drivers are currently available for the VIC20. Extended memory drivers

+ + A driver for any RAM at $A000-$BFFF. Supports 32 256 byte pages. Written and contributed by Marco van den Heuvel. +

+ Joystick drivers