From 1df61f7865bbd23eeb2006f601182b97e80fcc9b Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 8 Apr 2024 01:19:19 -0400 Subject: [PATCH] keen: improve IIgs support --- games/keen/Makefile | 2 +- games/keen/hardware.inc | 1 + games/keen/hardware_detect.s | 153 +++++++++++++++++++++++++++++++++++ games/keen/loader.s | 39 ++++++++- games/keen/zp.inc | 2 +- keyboard/README | 12 +++ 6 files changed, 205 insertions(+), 4 deletions(-) create mode 100644 games/keen/hardware_detect.s create mode 100644 keyboard/README diff --git a/games/keen/Makefile b/games/keen/Makefile index d92857c5..300d67b0 100644 --- a/games/keen/Makefile +++ b/games/keen/Makefile @@ -32,7 +32,7 @@ HELLO: hello.bas LOADER: loader.o ld65 -o LOADER loader.o -C ../../linker_scripts/apple2_1000.inc -loader.o: loader.s +loader.o: loader.s hardware_detect.s ca65 -o loader.o loader.s -l loader.lst #### diff --git a/games/keen/hardware.inc b/games/keen/hardware.inc index 8bd458c1..eb28ede9 100644 --- a/games/keen/hardware.inc +++ b/games/keen/hardware.inc @@ -12,6 +12,7 @@ TBCOLOR = $C022 ; IIgs text foreground / background colors NEWVIDEO = $C029 ; IIgs graphics modes SPEAKER = $C030 CLOCKCTL = $C034 ; bits 0-3 are IIgs border color +CYAREG = $C036 ; iigs motor detect and clock speed SET_GR = $C050 SET_TEXT = $C051 FULLGR = $C052 diff --git a/games/keen/hardware_detect.s b/games/keen/hardware_detect.s new file mode 100644 index 00000000..34cfb1f9 --- /dev/null +++ b/games/keen/hardware_detect.s @@ -0,0 +1,153 @@ +;==================== +; Hardware Detect + +; we mostly care about the model type +; TODO: for hi-res we might want to detect language card + +; Things we care about +; + Original Apple II / II+ have horrible keyboard support +; for platformers (only keydown events). If we detect IIe or +; later we can do better +; + Apple IIgs before ROM3 has broken lo-res PAGE2 support. +; we can enable the software workaround but it's slow + +hardware_detect: + + ;======================= + ; Hardware Detect Model + ;======================= + ; Yes Michaelangel007 I will eventually update linux_logo 6502 + + jsr detect_appleii_model + + lda APPLEII_MODEL + cmp #'g' + bne not_iigs + +is_a_iigs: + + ; enable 1MHz mode + ; see hw.accel.a in 4cade +setspeed: + lda CYAREG + and #$7f + sta CYAREG + + ; gr/text page2 handling broken on early IIgs models (before ROM3) + ; this enables the workaround + + jsr ROM_TEXT2COPY ; set alternate display mode on IIgs + + + ; set background color to black instead of blue + lda NEWVIDEO + and #%00011111 ; bit 7 = 0 -> IIgs Apple II-compat video modes + ; bit 6 = 0 -> IIgs 128K memory map same as IIe + ; bit 5 = 0 -> IIgs DHGR is color, not mono + ; bits 0-4 unchanged + sta NEWVIDEO + lda #$F0 + sta TBCOLOR ; white text on black background + lda #$00 + sta CLOCKCTL ; black border + sta CLOCKCTL ; set twice for VidHD + +not_iigs: + + + + ;=========================== + ; Check Apple II model + ;=========================== + ; this is mostly for IIc support + ; as it does interrupts differently + + ; some of this info from the document: + ; Apple II Family Identification Routines 2.2 + ; + + ; ' ' = Apple II + ; '+' = Apple II+ + ; 'e' = Apple IIe + ; 'c' = Apple IIc + ; 'g' = Apple IIgs + ; 'm' = mac L/C with board + ; 'j' = jplus + ; '3' = Apple III + +detect_appleii_model: + lda #' ' + + ldx $FBB3 + + ; II is $38 + ; J-plus is $C9 + ; II+ is $EA (so is III) + ; IIe and newer is $06 + + cpx #$38 ; ii + beq done_apple_detect + + + ; ii+ is EA FB1E=AD + ; iii is EA FB1E=8A 00 + + cpx #$EA + bne not_ii_iii +ii_or_iii: + + lda #'+' ; ii+/iii + + ldx $FB1E + cpx #$AD + beq done_apple_detect ; ii+ + + lda #'3' + bne done_apple_detect ; bra iii + +not_ii_iii: + lda #'j' ; jplus + cpx #$C9 + beq done_apple_detect + + + cpx #$06 + bne done_apple_detect + +apple_iie_or_newer: + + + + ldx $FBC0 ; $EA on a IIe + ; $E0 on a IIe enhanced + ; $00 on a IIc/IIc+ + + ; $FE1F = $60, IIgs + + beq apple_iic + + lda #'e' + cpx #$EA + beq done_apple_detect +; cpx #$E0 +; beq done_apple_detect + + ; should do something if not $E0 + + ; GS and IIe enhanced are the same, need to check + + sec ; set carry + jsr $FE1F + bcs done_apple_detect ;If carry then IIe enhanced + + ; get here we're a IIgs? + + lda #'g' + bne done_apple_detect + +apple_iic: + lda #'c' + +done_apple_detect: + sta APPLEII_MODEL + rts diff --git a/games/keen/loader.s b/games/keen/loader.s index 5768146a..b99edd59 100644 --- a/games/keen/loader.s +++ b/games/keen/loader.s @@ -48,6 +48,37 @@ filbuf = $3D6 ; filbuf: .res 4 ; = bit2tbl+86 loader_start: + jsr hardware_detect + + lda #model_string + sta OUTH + + lda APPLEII_MODEL + sta model_string+17 + + cmp #'g' + bne go_print + + lda #'s' + sta model_string+18 + +go_print: + + ldy #0 +print_model: + lda (OUTL),Y + beq print_model_done + ora #$80 + sta $7d0,Y + iny + jmp print_model +print_model_done: + + + + lda #LOAD_TITLE sta WHICH_LOAD @@ -267,10 +298,10 @@ quick_print: beq quick_print_done jsr COUT1 iny - jmp quick_print +; jmp quick_print quick_print_done: -; rts + rts ; jsr quick_print @@ -285,6 +316,8 @@ fnf_keypress: error_string: .byte "PLEASE INSERT DISK 1, PRESS RETURN",0 +model_string: +.byte "DETECTED APPLE II",0,0,0 @@ -679,6 +712,8 @@ step2: .byte $70, $2c, $26, $22, $1f, $1e, $1d, $1c sectbl: .byte $00,$0d,$0b,$09,$07,$05,$03,$01,$0e,$0c,$0a,$08,$06,$04,$02,$0f +.include "hardware_detect.s" + ; From $BA96 of DOS33 ;nibtbl: .res 128 ; = * ; .byte $00,$01,$98,$99,$02,$03,$9C,$04 ; $BA96 ; 00 diff --git a/games/keen/zp.inc b/games/keen/zp.inc index c6c9aed6..cc908f97 100644 --- a/games/keen/zp.inc +++ b/games/keen/zp.inc @@ -140,7 +140,7 @@ MARS_X = $A0 MARS_Y = $A1 INITIAL_SOUND = $A2 PLAY_END_SOUND = $A3 - +APPLEII_MODEL = $A4 WHICH_SLOT = $DA JS_BUTTON_STATE = $DB diff --git a/keyboard/README b/keyboard/README new file mode 100644 index 00000000..06a8d5fa --- /dev/null +++ b/keyboard/README @@ -0,0 +1,12 @@ +Apple II Keyboard Support + +Original Apple II / Apple II+ + + +Apple IIe + If you read $C010 (KEYRESET) bit #7 is "any key down" meaning + you can detect if a key is being held down + +Apple IIc / IIgs + Possibly have actual keyboard buffer you can enable, along + with interrupts?