1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-10-31 16:04:48 +00:00

Add embedded PLASMA sample

This commit is contained in:
dschmenk 2017-04-25 11:54:45 -07:00
parent 488f039494
commit 2118af149b
7 changed files with 2133 additions and 0 deletions

395
src/samplesrc/a2pwm/a2pwm.s Executable file
View File

@ -0,0 +1,395 @@
;****************************************************************
;*
;* PWM SOUND ROUTINES
;*
;****************************************************************
;*
;* PWM ZERO PAGE LOCATIONS
;*
SPEAKER = $C030
HFO = $08
LFO = $09
LFOINDEX= $0A ; IF LFOUSRH == 0
LFOUSRL = $0A
LFOUSRH = $0B
ATK = $0C
DCY = $0D
SUS = $0E
RLS = $0F
ATKINCL = $10
ATKINCH = $11
DCYINCL = $12
DCYINCH = $13
RLSINCL = $14
RLSINCH = $15
ADSRL = $16
ADSRH = $17
ADSRINCL= $18
ADSRINCH= $19
TONELEN = $1B
LPCNT = $1C
HFOCNT = $1D
LFOPOSL = $1E
LFOPOSH = $1F
LFOPTR = $00
LFOPTRL = LFOPTR
LFOPTRH = LFOPTRL+1
;*
;* PWM ENTRY POINT
;*
HILOPWM LDA LFOUSRL
LDX LFOUSRH
BNE + ; USER SUPPLIED WAVEFORM
LDX #>LFOTBL
ASL
ASL
ASL
ASL
ASL
+ STA LFOPTRL
STX LFOPTRH
PHP
SEI
LDY #$00
STY LFOPOSL
; STY LFOPOSH
STY LPCNT
STY ADSRL
; STY ADSRH
LDA #$02
STA HFOCNT
ATTACK LDX #$0F
LDA ATK
BEQ DECAY
LDX #$00
STA TONELEN
LDA ATKINCL
STA ADSRINCL
LDA ATKINCH
STA ADSRINCH
JSR HILOSND
DECAY LDA DCY
BEQ SUSTAIN
STA TONELEN
LDA #$00 ; REVERSE ATTACK RATE
SEC
SBC DCYINCL
STA ADSRINCL
LDA #$00
SBC DCYINCH
STA ADSRINCH
JSR HILOSND
SUSTAIN LDA SUS
BEQ RELEASE
STA TONELEN
LDA #$00 ; SUSTAIN DOESN'T ALTER VOLUME
STA ADSRINCL
STA ADSRINCH
JSR HILOSND
RELEASE LDA RLS
BEQ PWMEXIT
STA TONELEN
LDA #$00 ; REVERSE RELEASE RATE
SEC
SBC RLSINCL
STA ADSRINCL
LDA #$00
SBC RLSINCH
STA ADSRINCH
JSR HILOSND
PWMEXIT PLP
RTS
PWMSND CLC ; 1, 2
LDA ADSRL ; 2, 3
ADC ADSRINCL ; 2, 3
STA TMP ; 2, 3
TXA ; 1, 2
ADC ADSRINCH ; 2, 3
DEC LPCNT ; 2, 5
;------
;12,21
BNE HILOSND ; 2, 2
AND #$0F ; 2, 2
TAX ; 1, 2
LDA TMP ; 2, 3
STA ADSRL ; 2, 3
DEC TONELEN ; 2, 5
BEQ PWMRET ; 2, 2
DEC HFOCNT ; 2, 5
BEQ SPKRON ; 2, 2
CLC ; 1, 2
LDA LFOPOSL ; 2, 3
ADC LFO ; 2, 3
STA LFOPOSL ; 2, 3
TYA ; 1, 2
ADC #$00 ; 2, 2
AND #$1F ; 2, 2
TAY ; 1, 2
TXA ; 1, 2
ORA (LFOPTR),Y ; 2, 5
STA *+4 ; 3, 4
LDA MUL4X4 ; 3, 4
ASL ; 1, 2
STA SPKRPWM+1 ; 3, 4
LDA #>PWM1 ; 2, 2
ADC #$00 ; 2, 2
STA SPKRPWM+2 ; 3, 4
NOP ; 1, 2
JMP PWMSND ; 3, 3
;------
;55,79
; BNE HILOSND ; , 3
HILOSND DEC HFOCNT ; 2, 5
BNE + ; 2, 2
SPKRON BIT SPEAKER ; 3, 4
SPKRPWM JMP PWM1 ; 3, 3+62
;------
;10,79
; BNE HILOSND ; , 3
; DEC HFOCNT ; , 5
; BNE + ; , 3
+ BNE ++ ; 2, 3
++ NOP ; 1, 2
NOP ; 1, 2
NOP ; 1, 2
NOP ; 1, 2
NOP ; 1, 2
NOP ; 1, 2
NOP ; 1, 2
CLC ; 1, 2
LDA LFOPOSL ; 2, 3
ADC LFO ; 2, 3
STA LFOPOSL ; 2, 3
TYA ; 1, 2
ADC #$00 ; 2, 2
AND #$1F ; 2, 2
TAY ; 1, 2
TXA ; 1, 2
ORA (LFOPTR),Y ; 2, 5
STA *+4 ; 3, 4
LDA MUL4X4 ; 3, 4
ASL ; 1, 2
STA SPKRPWM+1 ; 3, 4
LDA #>PWM1 ; 2, 2
ADC #$00 ; 2, 2
STA SPKRPWM+2 ; 3, 4
JMP PWMSND ; 3, 3
;------
;44,79
PWMRET RTS
;*
;* 4 BIT x 4 BIT TO 3.5 BIT MULTIPLY TABLE
;*
!ALIGN 255,0
MUL4X4 !BYTE $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
!BYTE $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
!BYTE $00, $00, $00, $00, $00, $00, $00, $00, $20, $20, $20, $20, $20, $20, $20, $20
!BYTE $00, $00, $00, $00, $00, $00, $20, $20, $20, $20, $20, $20, $20, $20, $20, $20
!BYTE $00, $00, $00, $00, $20, $20, $20, $20, $20, $20, $20, $20, $40, $40, $40, $40
!BYTE $00, $00, $00, $00, $20, $20, $20, $20, $20, $20, $40, $40, $40, $40, $40, $40
!BYTE $00, $00, $00, $20, $20, $20, $20, $20, $40, $40, $40, $40, $40, $40, $60, $60
!BYTE $00, $00, $00, $20, $20, $20, $20, $40, $40, $40, $40, $40, $60, $60, $60, $60
!BYTE $00, $00, $20, $20, $20, $20, $40, $40, $40, $40, $60, $60, $60, $60, $80, $80
!BYTE $00, $00, $20, $20, $20, $20, $40, $40, $40, $60, $60, $60, $60, $80, $80, $80
!BYTE $00, $00, $20, $20, $20, $40, $40, $40, $60, $60, $60, $60, $80, $80, $80, $A0
!BYTE $00, $00, $20, $20, $20, $40, $40, $40, $60, $60, $60, $80, $80, $80, $A0, $A0
!BYTE $00, $00, $20, $20, $40, $40, $40, $60, $60, $60, $80, $80, $A0, $A0, $A0, $C0
!BYTE $00, $00, $20, $20, $40, $40, $40, $60, $60, $80, $80, $80, $A0, $A0, $C0, $C0
!BYTE $00, $00, $20, $20, $40, $40, $60, $60, $80, $80, $80, $A0, $A0, $C0, $C0, $E0
!BYTE $00, $00, $20, $20, $40, $40, $60, $60, $80, $80, $A0, $A0, $C0, $C0, $E0, $E0
LFOTBL !SOURCE "lfotbl.s"
!ALIGN 63,0
PWM1 BIT SPEAKER ; 3, 4
CLC ; 1, 2
LDA LFOPOSL ; 2, 3
ADC LFO ; 2, 3
STA LFOPOSL ; 2, 3
TYA ; 1, 2
ADC #$00 ; 2, 2
AND #$1F ; 2, 2
TAY ; 1, 2
TXA ; 1, 2
ORA (LFOPTR),Y ; 2, 5
STA *+4 ; 3, 4
LDA MUL4X4 ; 3, 4
ASL ; 1, 2
STA SPKRPWM+1 ; 3, 4
LDA #>PWM1 ; 2, 2
ADC #$00 ; 2, 2
STA SPKRPWM+2 ; 3, 4
LDA HFO ; 2, 3
STA HFOCNT ; 2, 3
JMP PWMSND ; 3, 3
;------
;43,61
!ALIGN 63,0
PWM2 CLC ; 1, 2
LDA LFOPOSL ; 2, 3
BIT SPEAKER ; 3, 4
ADC LFO ; 2, 3
STA LFOPOSL ; 2, 3
TYA ; 1, 2
ADC #$00 ; 2, 2
AND #$1F ; 2, 2
TAY ; 1, 2
TXA ; 1, 2
ORA (LFOPTR),Y ; 2, 5
STA *+4 ; 3, 4
LDA MUL4X4 ; 3, 4
ASL ; 1, 2
STA SPKRPWM+1 ; 3, 4
LDA #>PWM1 ; 2, 2
ADC #$00 ; 2, 2
STA SPKRPWM+2 ; 3, 4
LDA HFO ; 2, 3
STA HFOCNT ; 2, 3
JMP PWMSND ; 3, 3
;------
;43,62
!ALIGN 63,0
PWM3 CLC ; 1, 2
LDA LFOPOSL ; 2, 3
ADC LFO ; 2, 3
STA LFOPOSL ; 2, 3
BIT SPEAKER ; 3, 4
TYA ; 1, 2
ADC #$00 ; 2, 2
AND #$1F ; 2, 2
TAY ; 1, 2
TXA ; 1, 2
ORA (LFOPTR),Y ; 2, 5
STA *+4 ; 3, 4
LDA MUL4X4 ; 3, 4
ASL ; 1, 2
STA SPKRPWM+1 ; 3, 4
LDA #>PWM1 ; 2, 2
ADC #$00 ; 2, 2
STA SPKRPWM+2 ; 3, 4
LDA HFO ; 2, 3
STA HFOCNT ; 2, 3
JMP PWMSND ; 3, 3
;------
;43,61
!ALIGN 63,0
PWM4 CLC ; 1, 2
LDA LFOPOSL ; 2, 3
ADC LFO ; 2, 3
STA LFOPOSL ; 2, 3
TYA ; 1, 2
ADC #$00 ; 2, 2
AND #$1F ; 2, 2
TAY ; 1, 2
BIT SPEAKER ; 3, 4
TXA ; 1, 2
ORA (LFOPTR),Y ; 2, 5
STA *+4 ; 3, 4
LDA MUL4X4 ; 3, 4
ASL ; 1, 2
STA SPKRPWM+1 ; 3, 4
LDA #>PWM1 ; 2, 2
ADC #$00 ; 2, 2
STA SPKRPWM+2 ; 3, 4
LDA HFO ; 2, 3
STA HFOCNT ; 2, 3
JMP PWMSND ; 3, 3
;------
;43,61
!ALIGN 63,0
PWM5 CLC ; 1, 2
LDA LFOPOSL ; 2, 3
ADC LFO ; 2, 3
STA LFOPOSL ; 2, 3
TYA ; 1, 2
ADC #$00 ; 2, 2
AND #$1F ; 2, 2
TAY ; 1, 2
TXA ; 1, 2
ORA (LFOPTR),Y ; 2, 5
BIT SPEAKER ; 3, 4
STA *+4 ; 3, 4
LDA MUL4X4 ; 3, 4
ASL ; 1, 2
STA SPKRPWM+1 ; 3, 4
LDA #>PWM1 ; 2, 2
ADC #$00 ; 2, 2
STA SPKRPWM+2 ; 3, 4
LDA HFO ; 2, 3
STA HFOCNT ; 2, 3
JMP PWMSND ; 3, 3
;------
;43,61
!ALIGN 63,0
PWM6 CLC ; 1, 2
LDA LFOPOSL ; 2, 3
ADC LFO ; 2, 3
STA LFOPOSL ; 2, 3
TYA ; 1, 2
ADC #$00 ; 2, 2
AND #$1F ; 2, 2
TAY ; 1, 2
TXA ; 1, 2
ORA (LFOPTR),Y ; 2, 5
STA *+4 ; 3, 4
LDA MUL4X4 ; 3, 4
BIT SPEAKER ; 3, 4
ASL ; 1, 2
STA SPKRPWM+1 ; 3, 4
LDA #>PWM1 ; 2, 2
ADC #$00 ; 2, 2
STA SPKRPWM+2 ; 3, 4
LDA HFO ; 2, 3
STA HFOCNT ; 2, 3
JMP PWMSND ; 3, 3
;------
;43,61
!ALIGN 63,0
PWM7 CLC ; 1, 2
LDA LFOPOSL ; 2, 3
ADC LFO ; 2, 3
STA LFOPOSL ; 2, 3
TYA ; 1, 2
ADC #$00 ; 2, 2
AND #$1F ; 2, 2
TAY ; 1, 2
TXA ; 1, 2
ORA (LFOPTR),Y ; 2, 5
STA *+4 ; 3, 4
LDA MUL4X4 ; 3, 4
ASL ; 1, 2
STA SPKRPWM+1 ; 3, 4
LDA #>PWM1 ; 2, 2
ADC #$00 ; 2, 2
BIT SPEAKER ; 3, 4
STA SPKRPWM+2 ; 3, 4
LDA HFO ; 2, 3
STA HFOCNT ; 2, 3
JMP PWMSND ; 3, 3
;------
;43,61
!ALIGN 63,0
PWM8 CLC ; 1, 2
LDA LFOPOSL ; 2, 3
ADC LFO ; 2, 3
STA LFOPOSL ; 2, 3
TYA ; 1, 2
ADC #$00 ; 2, 2
AND #$1F ; 2, 2
TAY ; 1, 2
TXA ; 1, 2
ORA (LFOPTR),Y ; 2, 5
STA *+4 ; 3, 4
LDA MUL4X4 ; 3, 4
ASL ; 1, 2
STA SPKRPWM+1 ; 3, 4
LDA #>PWM1 ; 2, 2
ADC #$00 ; 2, 2
STA SPKRPWM+2 ; 3, 4
LDA HFO ; 2, 3
STA HFOCNT ; 2, 3
BIT SPEAKER ; 3, 4
JMP PWMSND ; 3, 3
;------
;43,61

267
src/samplesrc/a2pwm/hilopwm.pla Executable file
View File

@ -0,0 +1,267 @@
const inbuff = $200
const freemem = $0002
const FALSE = 0
const TRUE = !FALSE
//
// System variables.
//
word heap
//
// Periods of scale in second octave
//
byte scale[] = 166, 156, 148, 139, 132, 124, 117, 111, 104, 99, 93, 88, 83, 78
//
// Key mapping to note
//
byte keytone[] = 'A','S','E','D','R','F','G','Y','H','U','J','I','K','L'
//
// Which octave are we in
//
byte octave = 1
//
// FLO period and waveform
//
byte LFO, LFOmap
//
// Note duration
//
byte duration = 22
//
// Envelope parameters
//
byte atkLen = 2
byte dcyLen = 0
byte susLen = 4
byte relLen = 16
word atkRate = $07FF
word dcyRate = $0000
word relRate = $00FF
//
// Import utility routines
//
include "util.pla"
//
// Clear viewport to white
//
def clearWin
byte i, j
inverse
home
for j = 0 to 3
for i = 0 to 39; putc(' '); next
next
return gotoxy(0,0)
end
//
// Display LFO bar
//
def showLFO
byte LFObar
LFObar = (LFO+7)/8
grcolor(WHITE)
rect(34, 39, 6, 39, FALSE)
if LFObar < 32
grcolor(ORANGE)
rect(35, 38, 7, 38-LFObar, TRUE)
fin
if LFObar
grcolor(DRKBLU)
rect(35, 38, 39-LFObar, 38, TRUE)
fin
putsxy(36, 0, " ")
gotoxy(36, 0)
puti(LFO)
end
//
// Display LFO waveform
//
def showWaveform
byte i, mapBar
word mapPtr
//
// Get pointer to LFO waveform by calling PWM with zero note
//
envelope(0, 0, 0, 0, atkRate, dcyRate, relRate)
hilopwm(0, LFO, LFOmap)
mapPtr = *0 // Pointer at address 0
grcolor(WHITE)
rect(0, 33, 6, 39, FALSE)
for i = 0 to 31
mapBar = ^(mapPtr + i) >> 3
grcolor(BLACK)
vlin(7, 38-mapBar, i + 1)
grcolor(MAGENTA)
vlin(38 - mapBar, 38, i + 1)
grcolor(PURPLE)
vlin(37-mapBar, 38-mapBar, i + 1)
next
//
// Restore envelope
//
envelope(atkLen, dcyLen, susLen, relLen, atkRate, dcyRate, relRate)
end
//
// Display duration
//
def showDuration
byte left, right
if duration == 40
left = 0
right = 39
else
left = 19-duration/2
right = left + duration
fin
grcolor(BLACK)
if left > 0
rect(0, left-1, 0, 5, TRUE)
fin
if right < 39
rect(right+1, 39, 0, 5, TRUE)
fin
grcolor(AQUA)
rect(left, right, 0, 5, TRUE)
end
//
// Display octave
//
def showOctave
inverse
putsxy(0, 1, "----------------------------------------")
normal
putsxy(octave*10, 1, "----------")
inverse
end
//
// Recalc envelope parameters
//
def recalcEnv
atkLen = duration/8
relLen = duration/2
susLen = duration - atkLen - relLen
atkRate = $0FFF/atkLen
relRate = $0FFF/relLen
end
//
// Main loop
//
def main
byte quit, key, i
envelope(atkLen, dcyLen, susLen, relLen, atkRate, dcyRate, relRate)
quit = FALSE
repeat
if keypressed
key = toupper(getc)
when key
is $1B // ESC
quit = TRUE
break
is $15 // ->
if octave < 3
octave++
showOctave
fin
break
is $08 // <-
if octave > 0
octave--
showOctave
fin
break
is '1'
is '2'
is '3'
is '4'
is '5'
is '6'
is '7'
is '8'
LFOmap = key - '1'
showWaveform
break
is '<'
is ','
LFO--
showLFO
break
is '>'
is '.'
LFO++
showLFO
break
is '+'
is $0B // UP
if duration < 40
duration++
recalcEnv
envelope(atkLen, dcyLen, susLen, relLen, atkRate, dcyRate, relRate)
showDuration
fin
break
is '-'
is $0A // DOWN
if duration > 2
duration--
recalcEnv
envelope(atkLen, dcyLen, susLen, relLen, atkRate, dcyRate, relRate)
showDuration
fin
break
otherwise
for i = 0 to 13
if keytone[i] == key
if LFO == 0
hilopwm(scale[i]>>octave, LFO, 0)
else
hilopwm(scale[i]>>octave, LFO, LFOmap)
fin
break
fin
next
wend
fin
//LFO = pdl(0)
until quit
end
//
// Get heap start.
//
heap = *freemem
call($FDED, $8D, 0, 0, 0)
call($FDED, $91, 0, 0, 0)// CTRL-Q = turn off 80 column
call($FDED, $8D, 0, 0, 0)
^$C000 = 0 // Turn off 80STORE
grmode
clearview
showDuration
showWaveform
showLFO
putsxy(8, 0, "OSCILLATION OVERTHRUSTER")
normal
putsxy(2, 0, "1..8")
gotoxy(34, 0); putc('<')
gotoxy(39, 0); putc('>')
gotoxy(6, 3); putc('-')
gotoxy(32, 3); putc('+')
inverse
showOctave
normal
putsxy(0, 2, "<-")
putsxy(38, 2, "->")
inverse
putsxy(11, 3, "A S D F G H J K L")
normal
gotoxy(14, 2); putc('E')
gotoxy(16, 2); putc('R')
gotoxy(20, 2); putc('Y')
gotoxy(22, 2); putc('U')
gotoxy(24, 2); putc('I')
inverse
main
normal
textmode
done

BIN
src/samplesrc/a2pwm/lfo.po Executable file

Binary file not shown.

32
src/samplesrc/a2pwm/lfotbl.s Executable file
View File

@ -0,0 +1,32 @@
LFODWN !BYTE $F0 , $F0 , $E0 , $E0 , $D0 , $D0 , $C0 , $C0
!BYTE $B0 , $B0 , $A0 , $A0 , $90 , $90 , $80 , $80
!BYTE $70 , $70 , $60 , $60 , $50 , $50 , $40 , $40
!BYTE $30 , $30 , $20 , $20 , $10 , $10 , $00 , $00
LFOUP !BYTE $00 , $00 , $10 , $10 , $20 , $20 , $30 , $30
!BYTE $40 , $40 , $50 , $50 , $60 , $60 , $70 , $70
!BYTE $80 , $80 , $90 , $90 , $A0 , $A0 , $B0 , $B0
!BYTE $C0 , $C0 , $D0 , $D0 , $E0 , $E0 , $F0 , $F0
LFOREXP !BYTE $F0 , $D0 , $C0 , $B0 , $A0 , $90 , $90 , $80
!BYTE $70 , $60 , $60 , $50 , $50 , $40 , $40 , $40
!BYTE $30 , $30 , $30 , $20 , $20 , $20 , $20 , $10
!BYTE $10 , $10 , $10 , $10 , $10 , $00 , $00 , $00
LFOEXP !BYTE $00 , $00 , $00 , $10 , $10 , $10 , $10 , $10
!BYTE $10 , $20 , $20 , $20 , $20 , $30 , $30 , $30
!BYTE $40 , $40 , $40 , $50 , $50 , $60 , $60 , $70
!BYTE $80 , $90 , $90 , $A0 , $B0 , $C0 , $D0 , $F0
LFSAW !BYTE $00 , $10 , $20 , $30 , $40 , $50 , $60 , $70
!BYTE $80 , $90 , $A0 , $B0 , $C0 , $D0 , $E0 , $F0
!BYTE $F0 , $E0 , $D0 , $C0 , $B0 , $A0 , $90 , $80
!BYTE $70 , $60 , $50 , $40 , $30 , $20 , $10 , $00
LFOCOS !BYTE $00 , $10 , $10 , $20 , $30 , $40 , $50 , $60
!BYTE $80 , $90 , $B0 , $C0 , $D0 , $E0 , $F0 , $F0
!BYTE $F0 , $F0 , $F0 , $E0 , $D0 , $C0 , $B0 , $90
!BYTE $80 , $60 , $50 , $40 , $30 , $20 , $10 , $10
LFOSIN !BYTE $00 , $20 , $30 , $50 , $60 , $80 , $90 , $A0
!BYTE $B0 , $C0 , $D0 , $E0 , $E0 , $F0 , $F0 , $F0
!BYTE $F0 , $F0 , $F0 , $F0 , $E0 , $E0 , $D0 , $C0
!BYTE $B0 , $A0 , $90 , $80 , $60 , $50 , $30 , $20
LFOOCOS !BYTE $F0 , $F0 , $F0 , $E0 , $E0 , $E0 , $D0 , $C0
!BYTE $C0 , $B0 , $A0 , $90 , $90 , $90 , $80 , $80
!BYTE $80 , $80 , $80 , $90 , $90 , $90 , $A0 , $B0
!BYTE $C0 , $C0 , $D0 , $E0 , $E0 , $E0 , $F0 , $F0

28
src/samplesrc/a2pwm/makefile Executable file
View File

@ -0,0 +1,28 @@
.SUFFIXES =
AFLAGS = -o $@
HILOPWM = hilopwm.bin
PLASM = ../../plasm
#
# Image filetypes for Virtual ][
#
PLATYPE = .\$$ED
BINTYPE = .BIN
SYSTYPE = .SYS
TXTTYPE = .TXT
#
# Image filetypes for CiderPress
#
#RELTYPE = \#FE1000
#INTERPTYPE = \#050000
#BINTYPE = \#060000
#SYSTYPE = \#FF2000
#TXTTYPE = \#040000
all: $(HILOPWM)
clean:
-rm *.o *~ *.a *.bin
$(HILOPWM): a2pwm.s util.pla hilopwm.pla pwmvm.s $(PLASM)
./$(PLASM) -A < hilopwm.pla > hilopwm.a
acme -o $(HILOPWM) pwmvm.s

1007
src/samplesrc/a2pwm/pwmvm.s Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,404 @@
//
// Colors
//
const BLACK = 0
const MAGENTA = 1
const DRKBLU = 2
const PURPLE = 3
const DRKGRN = 4
const GREY = 5
const MEDBLU = 6
const LGTBLU = 7
const BROWN = 8
const ORANGE = 9
const GRAY = 10
const PINK = 11
const LGTGRN = 12
const YELLOW = 13
const AQUA = 14
const WHITE = 15
word txt1scrn[] = $0400,$0480,$0500,$0580,$0600,$0680,$0700,$0780
word = $0428,$04A8,$0528,$05A8,$0628,$06A8,$0728,$07A8
word = $0450,$04D0,$0550,$05D0,$0650,$06D0,$0750,$07D0
//
// CALL 6502 ROUTINE
// CALL(ADDR, AREG, XREG, YREG, STATUS)
//
asm call
PHP
LDA ESTKL+4,X
STA CALL6502+1
LDA ESTKH+4,X
STA CALL6502+2
LDA ESTKL,X
PHA
LDA ESTKL+1,X
TAY
LDA ESTKL+3,X
PHA
LDA ESTKL+2,X
INX
INX
INX
INX
STX ESP
TAX
PLA
PLP
CALL6502 JSR $FFFF
PHP
STA REGVALS+0
STX REGVALS+1
STY REGVALS+2
PLA
STA REGVALS+3
LDX ESP
LDA #<REGVALS
LDY #>REGVALS
STA ESTKL,X
STY ESTKH,X
PLP
RTS
REGVALS !FILL 4
end
//
// SET MEMORY TO VALUE
// MEMSET(ADDR, VALUE, SIZE)
// With optimizations from Peter Ferrie
//
asm memset
LDA ESTKL+2,X
STA DSTL
LDA ESTKH+2,X
STA DSTH
LDY ESTKL,X
BEQ +
INC ESTKH,X
LDY #$00
+ LDA ESTKH,X
BEQ SETMEX
SETMLPL CLC
LDA ESTKL+1,X
SETMLPH STA (DST),Y
DEC ESTKL,X
BEQ ++
- INY
BEQ +
-- BCS SETMLPL
SEC
LDA ESTKH+1,X
BCS SETMLPH
+ INC DSTH
BNE --
++ DEC ESTKH,X
BNE -
SETMEX INX
INX
RTS
end
//
// COPY MEMORY
// MEMCPY(DSTADDR, SRCADDR, SIZE)
//
asm memcpy
INX
INX
LDA ESTKL-2,X
ORA ESTKH-2,X
BEQ CPYMEX
LDA ESTKL-1,X
CMP ESTKL,X
LDA ESTKH-1,X
SBC ESTKH,X
BCC REVCPY
;
; FORWARD COPY
;
LDA ESTKL,X
STA DSTL
LDA ESTKH,X
STA DSTH
LDA ESTKL-1,X
STA SRCL
LDA ESTKH-1,X
STA SRCH
LDY ESTKL-2,X
BEQ FORCPYLP
INC ESTKH-2,X
LDY #$00
FORCPYLP LDA (SRC),Y
STA (DST),Y
INY
BNE +
INC DSTH
INC SRCH
+ DEC ESTKL-2,X
BNE FORCPYLP
DEC ESTKH-2,X
BNE FORCPYLP
RTS
;
; REVERSE COPY
;
REVCPY ;CLC
LDA ESTKL-2,X
ADC ESTKL,X
STA DSTL
LDA ESTKH-2,X
ADC ESTKH,X
STA DSTH
CLC
LDA ESTKL-2,X
ADC ESTKL-1,X
STA SRCL
LDA ESTKH-2,X
ADC ESTKH-1,X
STA SRCH
DEC DSTH
DEC SRCH
LDY #$FF
LDA ESTKL-2,X
BEQ REVCPYLP
INC ESTKH-2,X
REVCPYLP LDA (SRC),Y
STA (DST),Y
DEY
CPY #$FF
BNE +
DEC DSTH
DEC SRCH
+ DEC ESTKL-2,X
BNE REVCPYLP
DEC ESTKH-2,X
BNE REVCPYLP
CPYMEX RTS
end
//
// Unsigned word comparisons.
//
asm uword_isge
LDA ESTKL+1,X
CMP ESTKL,X
LDA ESTKH+1,X
SBC ESTKH,X
LDA #$FF
ADC #$00
EOR #$FF
STA ESTKL+1,X
STA ESTKH+1,X
INX
RTS
end
asm uword_isle
LDA ESTKL,X
CMP ESTKL+1,X
LDA ESTKH,X
SBC ESTKH+1,X
LDA #$FF
ADC #$00
EOR #$FF
STA ESTKL+1,X
STA ESTKH+1,X
INX
RTS
end
asm uword_isgt
LDA ESTKL,X
CMP ESTKL+1,X
LDA ESTKH,X
SBC ESTKH+1,X
LDA #$FF
ADC #$00
STA ESTKL+1,X
STA ESTKH+1,X
INX
RTS
end
asm uword_islt
LDA ESTKL+1,X
CMP ESTKL,X
LDA ESTKH+1,X
SBC ESTKH,X
LDA #$FF
ADC #$00
STA ESTKL+1,X
STA ESTKH+1,X
INX
RTS
end
//
// Addresses of internal routines.
//
asm _hilopwm
TXA
PHA
JSR HILOPWM
PLA
TAX
DEX
RTS
end
asm toupper
LDA ESTKL,X
TOUPR AND #$7F
CMP #'a'
BCC +
CMP #'z'+1
BCS +
SBC #$1F
+ STA ESTKL,X
RTS
end
//
// CONSOLE I/O
//
asm putc
LDA ESTKL,X
; JSR TOUPR
ORA #$80
JMP $FDF0
end
asm getc
DEX
- LDA $C000
BPL -
BIT $C010
AND #$7F
STA ESTKL,X
LDA #$00
STA ESTKH,X
RTS
end
def keypressed
return ^$C000 >= 128
end
def pdl(num)
return call($FB1E, 0, num, 0, 0)->2
end
def bttn(num)
return (^$C061+num) >= 128
end
def putln
return putc($0D)
end
def puts(str)
byte i
for i = 1 to ^str
putc(^(str+i))
next
end
def puti(i)
byte numstr[7]
byte place, sign
place = 6
if i < 0
sign = 1
i = -i
else
sign = 0
fin
while i >= 10
numstr[place] = i % 10 + '0'
i = i / 10
place--
loop
numstr[place] = i + '0'
place--
if sign
numstr[place] = '-'
place--
fin
numstr[place] = 6 - place
return puts(@numstr[place])
end
def normal
^$32 = $FF
end
def inverse
^$32 = $3F
end
def gotoxy(x, y)
^$24 = x + ^$20
return call($FB5B, y + ^$22, 0, 0, 0)
end
def home
return call($FC58, 0, 0, 0, 0)
end
def putsxy(x, y, str)
gotoxy(x, y)
return puts(str)
end
def textmode
call($FB39, 0, 0, 0, 0) // textmode()
return home
end
//
// Clear viewport to white
//
def clearview
byte i
word c
inverse
c = ' ' | $80 & ^$32
c = c | (c << 8)
for i = ^$22 to ^$23
memset(txt1scrn[i] + ^$20, c, ^$21)
next
return gotoxy(0,0)
end
def grmode
call($FB2F, 0, 0, 0, 0) // initmode()
call($FB40, 0, 0, 0, 0) // grmode()
return home
end
def grcolor(color)
return call($F864, color, 0, 0, 0)
end
def plot(x, y)
return call($F800, y, 0, x, 0)
end
def hlin(left, right, y)
^$2C = right;
return call($F819, y, 0, left, 0)
end
def vlin(top, bottom, x)
^$2D = bottom;
return call($F828, top, 0, x, 0)
end
def rect(left, right, top, bottom, fill)
byte y
hlin(left, right, top)
hlin(left, right, bottom)
top++
bottom--
if fill
for y = top to bottom
hlin(left, right, y)
next
else
vlin(top, bottom, left)
vlin(top, bottom, right)
fin
end
//
// HFO/LFO PWM sound routines
//
def envelope(attack, decay, sustain, release, ainc, dinc, rinc)
^$0C = attack
^$0D = decay
^$0E = sustain
^$0F = release
*$10 = ainc
*$12 = dinc
*$14 = rinc
end
def hilopwm(HFO, LFO, LFOusr)
^$08 = HFO
^$09 = LFO
*$0A = LFOusr
return _hilopwm
end