Skip to content

Commit

Permalink
Apple2: implement sleep using MONWAIT
Browse files Browse the repository at this point in the history
Also publish apple2_slowdown() and apple2_speedup() that could be
useful to users, and refactor to only store one apple2_ostype variable.
  • Loading branch information
colinleroy committed Jan 14, 2024
1 parent 8c329df commit 1015bc6
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 18 deletions.
2 changes: 2 additions & 0 deletions doc/apple2.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ usage.
<item>rebootafterexit
<item>ser_apple2_slot
<item>tgi_apple2_mix
<item>apple2_slowdown
<item>apple2_speedup
</itemize>


Expand Down
40 changes: 40 additions & 0 deletions doc/funcref.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ function.

<itemize>
<item>_dos_type
<item><ref id="apple2_slowdown" name="apple2_slowdown">
<item><ref id="apple2_speedup" name="apple2_speedup">
<item><ref id="get_ostype" name="get_ostype">
<item><ref id="gmtime_dt" name="gmtime_dt">
<item><ref id="mktime_dt" name="mktime_dt">
Expand All @@ -103,7 +105,11 @@ function.

<itemize>
<item>_dos_type
<item><ref id="apple2_slowdown" name="apple2_slowdown">
<item><ref id="apple2_speedup" name="apple2_speedup">
<item><ref id="get_ostype" name="get_ostype">
<item><ref id="gmtime_dt" name="gmtime_dt">
<item><ref id="mktime_dt" name="mktime_dt">
<item>rebootafterexit
<item><ref id="videomode" name="videomode">
</itemize>
Expand Down Expand Up @@ -1470,6 +1476,40 @@ used in presence of a prototype.
</quote>


<sect1>apple2_slowdown<label id="apple2_slowdown"><p>

<quote>
<descrip>
<tag/Function/Forces the Apple IIgs CPU to 1MHz
<tag/Header/<tt/<ref id="apple2.h" name="apple2.h">/
<tag/Declaration/<tt/void __fastcall__ apple2_slowdown (void);/
<tag/Description/The <tt/apple2_slowdown/ function toggles the Apple IIgs CPU
to 1MHz.
<tag/Notes/<itemize>
<item>This function is only available on Apple II.
</itemize>
<tag/Availability/cc65
</descrip>
</quote>


<sect1>apple2_speedup<label id="apple2_speedup"><p>

<quote>
<descrip>
<tag/Function/Sets the Apple IIgs CPU to the user preferred speed
<tag/Header/<tt/<ref id="apple2.h" name="apple2.h">/
<tag/Declaration/<tt/void __fastcall__ apple2_speedup (void);/
<tag/Description/The <tt/apple2_speedup/ function toggles the Apple IIgs CPU
back to the speed set in the IIgs control panel.
<tag/Notes/<itemize>
<item>This function is only available on Apple II.
</itemize>
<tag/Availability/cc65
</descrip>
</quote>


<sect1>assert<label id="assert"><p>

<quote>
Expand Down
33 changes: 33 additions & 0 deletions libsrc/apple2/cpuspeed.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;
; Colin Leroy-Mira <[email protected]>, 2024
;
; void __fastcall__ apple2_slowdown(void)
; void __fastcall__ apple2_speedup(void)
;

.export _apple2_slowdown
.export _apple2_speedup
.import apple2_ostype

.include "apple2.inc"

_apple2_slowdown:
bit apple2_ostype
bpl :+
lda CYAREG
sta cyareg_orig
and #%01111111
sta CYAREG
: rts

_apple2_speedup:
bit apple2_ostype
bpl :+
lda cyareg_orig
sta CYAREG
: rts

.bss

cyareg_orig:
.res 1
9 changes: 5 additions & 4 deletions libsrc/apple2/get_ostype.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;

.constructor initostype, 9
.export _get_ostype
.export _get_ostype, apple2_ostype

; Identify machine according to:
; Apple II Miscellaneous TechNote #7, Apple II Family Identification
Expand All @@ -18,7 +18,7 @@ initostype:
bcs nogs
tya
ora #$80
done: sta ostype
done: sta apple2_ostype
rts
nogs: ldx #$FF
next: inx
Expand Down Expand Up @@ -61,10 +61,11 @@ value: .byte $38, $10 ; Apple ][
.code

_get_ostype:
lda ostype
lda apple2_ostype
ldx #$00
rts

.segment "INIT"

ostype: .res 1
apple2_ostype:
.res 1
38 changes: 38 additions & 0 deletions libsrc/apple2/sleep.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;
; Colin Leroy-Mira <[email protected]>, 2024
;
; void __fastcall__ sleep(unsigned s)
;
;

.export _sleep
.import _apple2_slowdown
.import _apple2_speedup
.importzp tmp1

MONWAIT := $FCA8

_sleep:
stx tmp1
tay
ora tmp1
beq out
jsr _apple2_slowdown; Down to 1MHz for consistency around MONWAIT
bit $C082
sleep_1s:
ldx #10 ; Loop 10 times
: lda #200 ; About 100ms
jsr MONWAIT
dex
bne :-
dey
bne sleep_1s
dec tmp1
bmi done
ldy #$FF
bne sleep_1s
done:
bit $C080
jsr _apple2_speedup
out:
rts
16 changes: 2 additions & 14 deletions libsrc/apple2/waitvsync.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,15 @@
;
.ifdef __APPLE2ENH__

.constructor initvsync
.export _waitvsync
.import _get_ostype
.import apple2_ostype

.include "apple2.inc"

.segment "ONCE"

initvsync:
jsr _get_ostype
sta ostype
rts

.code

_waitvsync:
bit ostype
bit apple2_ostype
bmi iigs ; $8x
bvs iic ; $4x

Expand Down Expand Up @@ -53,8 +45,4 @@ iic: sei
cli
rts

.segment "INIT"

ostype: .res 1

.endif ; __APPLE2ENH__

0 comments on commit 1015bc6

Please sign in to comment.