Jump to content
xxl

simplest GTIA beeper engine

Recommended Posts

MusicStudio Engine for GTIA (source code)

 

:D

 

		    opt h+l+o+
gractl		  equ $d01d
consol		  equ $d01f
skctl		 equ $d20f
dmactl		  equ $d400
nmien		   equ $d40e
S_REG		   equ $f0
speed		   equ $f1
_channel	    equ $f2 ; 4 byte
		    org $2000
run_adr		 sei
		    lda #$00
		    sta nmien
		    sta gractl
		    sta dmactl
music_studio_stack
		    tsx
		    stx S_REG
		    ldx #$03
_lch		    lda _ch1,x
		    sta _channel,x
		    dex
		    bpl _lch
_loop		   lda skctl
		    and #$04
		    bne _cont
		    ldx S_REG
		    txs
		    rts
_cont		   ldx #$00
_load		   lda (_channel,x)
		    bpl _80_1
		    lda _ch1,x
		    sta _channel,x
		    lda _ch1+1,x
		    sta _channel+1,x
		    lda (_channel,x)
_80_1		 inc _channel,x
		    bne _80_2
		    inc _channel+1,x
_80_2		 tay
		    lda _nuty,y
		    pha
		    pha
		    pha
		    sec
		    sbc #$01
		    pha
		    beq _80_en1
		    lda #$08
_80_en1		 pha
		    lda #$00
		    pha
		    txa
		    eor #%10
		    tax				
		    bne _load
		    tay ; =0
		    lda music_speed
		    sta speed
_iloop		  tsx
_2kolej		 lda $0101,x
		    sta consol
		    dec $0105,x
		    bne _2kl
		    eor $0102,x
		    sta $0101,x
		    lda $0106,x
		    sta $0105,x
		    lda $0104,x
		    cmp #$20
		    bcs _2kl
		    inc $0106,x
_2kl		    dec $0103,x
		    bne _2kn
		    lda $0101,x
		    eor $0102,x
		    sta $0101,x
		    lda $0106,x
		    sta $0103,x
		    dec $0103,x
_2kn
		    txa
		    ;clc		  ; too slow, replace with sbx
		    ;adc #$06
		    ;tax
		    sbx #$100-$06 ; +6
		    cpx S_REG
		    bne _2kolej
	   
		    dey
		    bne _iloop
		    dec speed
		    bne _iloop
		    txs
		    jmp _loop
_nuty   .byte $FF,$F0,$E3,$D7,$CB,$C0,$B4,$AB
    .byte $A1,$97,$90,$88,$80,$79,$72,$6C
    .byte $66,$60,$5B,$56,$51,$4C,$48,$44
    .byte $40,$3D,$39,$36,$33,$30,$2D,$2B
    .byte $28,$26,$24,$22,$20,$1E,$1C,$1B
    .byte $19,$18,$17,$15,$14,$13,$12,$11
    .byte $10,$01
music_speed	 .byte $0f
_ch1		    .word kanal1
_ch2		    .word kanal2
  
kanal1  .byte $00,$0C,$00,$0C,$00,$0C,$00,$0C
    .byte $08,$14,$08,$14,$05,$11,$05,$11
    .byte $00,$0C,$00,$0C,$00,$0C,$00,$0C
    .byte $08,$14,$08,$14,$05,$11,$05,$07
    .byte $00,$0C,$00,$0C,$00,$0C,$00,$0C
    .byte $08,$14,$08,$14,$05,$11,$05,$07
    .byte $00,$0C,$00,$0C,$00,$0C,$00,$0C
    .byte $08,$14,$08,$14,$05,$11,$05,$07
    .byte $00,$0C,$25,$0C,$00,$0C,$25,$0C
    .byte $03,$0F,$25,$0F,$03,$0F,$25,$25
    .byte $08,$14,$25,$14,$08,$14,$25,$14
    .byte $05,$11,$25,$11,$05,$11,$25,$25
    .byte $00,$0C,$25,$0C,$00,$0C,$00,$0C
    .byte $03,$0F,$25,$0F,$03,$0F,$25,$0F
    .byte $08,$14,$25,$14,$08,$14,$25,$14
    .byte $05,$11,$25,$11,$07,$25,$25,$25
    .byte $03,$0F,$25,$0F,$03,$0F,$25,$0F
    .byte $05,$11,$25,$11,$05,$11,$25,$25
    .byte $00,$0C,$25,$0C,$00,$0C,$25,$0C
    .byte $0A,$16,$25,$16,$0A,$25,$0A,$25
    .byte $03,$0F,$25,$0F,$03,$0F,$25,$25
    .byte $05,$11,$25,$11,$05,$11,$25,$25
    .byte $00,$0C,$25,$0C,$00,$0C,$25,$0C
    .byte $0A,$16,$25,$16,$0A,$25,$0A,$25
    .byte $00,$0C,$25,$0C,$00,$0C,$25,$0C
    .byte $00,$0C,$25,$0C,$07,$05,$25,$25
    .byte $00,$0C,$25,$0C,$00,$0C,$25,$0C
    .byte $00,$0C,$25,$0C,$07,$25,$03,$25
    .byte $30,$30,$31,$30,$30,$31,$2D,$2D
    .byte $31,$2B,$2B,$31,$27,$31,$27,$31
    .byte $30,$30,$30,$30,$30,$30,$2D,$2D
    .byte $2D,$2A,$2A,$2A,$27,$27,$27,$27
    .byte $18,$1F,$18,$1D,$1F,$18,$22,$1F
    .byte $18,$1D,$1F,$18,$24,$1F,$22,$24
    .byte $18,$1F,$22,$1D,$1F,$18,$22,$1F
    .byte $18,$1D,$1B,$1F,$1A,$1D,$16,$1A
    .byte $18,$1F,$18,$1D,$1F,$18,$22,$1F
    .byte $18,$1D,$1F,$18,$24,$1F,$22,$24
    .byte $18,$1F,$22,$1D,$1F,$18,$22,$1F
    .byte $18,$1D,$1B,$18,$1A,$1B,$16,$1A
    .byte $ff
   
kanal2  .byte $00,$0C,$00,$0C,$00,$0C,$00,$0C
    .byte $08,$14,$08,$14,$05,$11,$05,$11
    .byte $00,$0C,$00,$0C,$00,$0C,$00,$0C
    .byte $08,$14,$08,$14,$05,$11,$05,$07
    .byte $00,$0C,$25,$0C,$00,$0C,$25,$0C
    .byte $08,$14,$25,$14,$05,$11,$25,$25
    .byte $00,$0C,$25,$0C,$00,$0C,$25,$0C
    .byte $08,$14,$25,$14,$05,$25,$05,$25
    .byte $1F,$0C,$1F,$0C,$1D,$1F,$00,$18
    .byte $03,$18,$1B,$18,$03,$18,$1B,$18
    .byte $1F,$14,$1F,$14,$1D,$1F,$08,$18
    .byte $05,$18,$1B,$18,$1F,$1D,$1B,$1D
    .byte $1F,$0C,$1F,$0C,$1D,$1B,$25,$18
    .byte $03,$18,$1B,$18,$03,$18,$1F,$18
    .byte $1F,$14,$1F,$14,$1D,$1B,$08,$18
    .byte $05,$18,$1B,$1D,$1F,$1D,$1B,$1A
    .byte $18,$0F,$18,$0F,$16,$18,$03,$13
    .byte $05,$18,$1B,$1D,$1F,$1D,$1B,$1D
    .byte $18,$0C,$1A,$0C,$1B,$18,$00,$1F
    .byte $0A,$1D,$1B,$1D,$1F,$1D,$1B,$1D
    .byte $18,$0F,$18,$0F,$16,$18,$03,$13
    .byte $05,$1D,$1B,$1D,$1F,$1D,$1B,$1A
    .byte $18,$0C,$18,$1A,$1B,$18,$00,$1F
    .byte $0A,$1F,$1D,$1B,$1D,$1B,$1A,$16
    .byte $00,$0C,$00,$0C,$00,$0C,$00,$0C
    .byte $00,$0C,$00,$0C,$07,$05,$03,$05
    .byte $00,$0C,$00,$0C,$00,$0C,$00,$0C
    .byte $00,$0C,$00,$0C,$07,$05,$03,$02
    .byte $30,$30,$30,$30,$30,$30,$2D,$2D
    .byte $2D,$2B,$2B,$2A,$27,$27,$27,$27
    .byte $30,$30,$31,$30,$30,$31,$2D,$2D
    .byte $31,$2A,$2A,$31,$27,$31,$27,$31
    .byte $18,$1F,$31,$1D,$1F,$31,$22,$1F
    .byte $31,$1D,$1F,$31,$24,$31,$22,$31
    .byte $18,$1F,$31,$1D,$1F,$31,$22,$1F
    .byte $31,$1D,$1B,$31,$1A,$31,$16,$31
    .byte $18,$1F,$31,$1D,$1F,$31,$22,$1F
    .byte $31,$1D,$1F,$31,$24,$31,$22,$31
    .byte $18,$1F,$31,$1D,$1F,$31,$22,$1F
    .byte $31,$1D,$1B,$31,$1A,$31,$16,$31
    .byte $ff
    org $2e0
    .word a(run_adr)

music_studio_stack.obx

  • Like 7

Share this post


Link to post
Share on other sites

Sounds really cool. Could you explain a bit how the routine works?

Edited by JAC!

Share this post


Link to post
Share on other sites

nice obfuscation :D. try remove stack usage...

Share this post


Link to post
Share on other sites

Hmm, the stack usage to use S as counter was the obvious part for me. I rather wonder about the nuty and the lda/eor/sta/dec sequence. Maybe I should add that I have no clue about PWM or whatever this is.

Edited by JAC!

Share this post


Link to post
Share on other sites

Very nice.

First I have to say that I don´t understand most of the code.

 

Using WUDSN I get an error saying:

 

 

Compiler 'MADS' output:

                               sbx #$100-$06 ; +6
/Users/skriegel/Documents/eclipse/Atari/gtia_sound.asm (87) ERROR: Undeclared macro SBX (BANK=0)

 

Using this works:

 

 

                                clc              ; too slow, replace with sbx
                               adc #$06
                               tax
                               ;sbx #$100-$06 ; +6

 

At least in the emulator (Atari800MacX on Mac Book Pro) it´s not too slow.

Share this post


Link to post
Share on other sites

SBX is an illegal opcode, so you need a recent MADS version >=1.9.2 which supports illegal opcodes also.

I haven't used illegal opcodes in MADS yet (is on the WUDSN todo list).

Maybe also a compiler switch is required to allow them (like /U in ATASM).

Share this post


Link to post
Share on other sites

lda $0106,x

sta $0103,x ; 5

dec $0103,x ; 7

 

better

 

 

lda $0106,x

sec ; 2

sbc #$01 ; 2

sta $0103,x ; 5

Share this post


Link to post
Share on other sites

ok. GTIA music is nice... lets play on PIA :-)

 

pactl		 equ $d302
		 org $2000
run_adr		 equ *
		 sei
		 lda #%00000000
		 sta nmien
		 sta gractl
		 sta dmactl
speed		 equ $f1
_channel	 equ $f2 ; 4 bajty
zpage		 equ $f6 ; $0a bajty
music_studio_zpage
	 ldx #3
_lch	 lda _ch1,x
	 sta _channel,x
	 dex
	 bpl _lch
_row	 lda skctl
 and #$04
 bne _cont
	 rts
_cont		
	 ldx #0
_load	 lda (_channel,x)
	 bpl _80_1
	
	 lda _ch1,x		 ; reload track
	 sta _channel,x
	 lda _ch1+1,x
	 sta _channel+1,x
	 lda (_channel,x)
	
_80_1	 inc _channel,x
	 bne _80_2
 inc _channel+1,x
_80_2	 tay
		 txa
		 lsr @
		 tax
	 lda _nuty,y
	 sta zpage+$00,x
	 sta zpage+$02,x
	 sta zpage+$04,x
	 sec
	 sbc #1
	 sta zpage+$06,x
	 beq _80_en1
	 lda #$38				 ; :-)
_80_en1	 sta zpage+$08,x
	 lda #$30				 ; :-)
	 sta zpage+$0a,x
	 inx
	 inx
	 cpx #$02
	 beq _load
	 lda music_speed
	 sta speed
	 ldy #$00
_loop
	 ldx #$00
_2kolej	 lda zpage+$0a,x
	 sta PACTL			 ; :-)
	 dec zpage+$02,x
	 bne _skp
	 eor zpage+$08,x
	 sta zpage+$0a,x
	 lda zpage+$00,x
	 sta zpage+$02,x
	 lda zpage+$04,x
	 cmp #$20
	 bcs _skp
	 inc zpage+$00,x
_skp	 dec zpage+$06,x
	 bne _skp1
	 lda zpage+$0a,x
	 eor zpage+$08,x
	 sta zpage+$0a,x
	 lda zpage+$00,x
	 sec
	 sbc #$01
	 sta zpage+$06,x
_skp1
	 inx
	 cpx #$02
	 bne _2kolej
	
	 dey
	 bne _loop
	 dec speed
	 bne _loop
	 jmp _row
_nuty
 dta $FF,$F0,$E3,$D7,$CB,$C0,$B4,$AB,$A1,$97,$90,$88,$80,$79,$72,$6C
 dta $66,$60,$5B,$56,$51,$4C,$48,$44,$40,$3D,$39,$36,$33,$30,$2D,$2B
 dta $28,$26,$24,$22,$20,$1E,$1C,$1B,$19,$18,$17,$15,$14,$13,$12,$11
 dta $10,$01

music_speed	 .byte $0f
_ch1		 .word kanal1
_ch2		 .word kanal2


kanal1 dta $00,$0C,$00,$0C,$00,$0C,$00,$0C
 dta $08,$14,$08,$14,$05,$11,$05,$11
 dta $00,$0C,$00,$0C,$00,$0C,$00,$0C
 dta $08,$14,$08,$14,$05,$11,$05,$07
 dta $00,$0C,$00,$0C,$00,$0C,$00,$0C
 dta $08,$14,$08,$14,$05,$11,$05,$07
 dta $00,$0C,$00,$0C,$00,$0C,$00,$0C
 dta $08,$14,$08,$14,$05,$11,$05,$07
 dta $00,$0C,$25,$0C,$00,$0C,$25,$0C
 dta $03,$0F,$25,$0F,$03,$0F,$25,$25
 dta $08,$14,$25,$14,$08,$14,$25,$14
 dta $05,$11,$25,$11,$05,$11,$25,$25
 dta $00,$0C,$25,$0C,$00,$0C,$00,$0C
 dta $03,$0F,$25,$0F,$03,$0F,$25,$0F
 dta $08,$14,$25,$14,$08,$14,$25,$14
 dta $05,$11,$25,$11,$07,$25,$25,$25
 dta $03,$0F,$25,$0F,$03,$0F,$25,$0F
 dta $05,$11,$25,$11,$05,$11,$25,$25
 dta $00,$0C,$25,$0C,$00,$0C,$25,$0C
 dta $0A,$16,$25,$16,$0A,$25,$0A,$25
 dta $03,$0F,$25,$0F,$03,$0F,$25,$25
 dta $05,$11,$25,$11,$05,$11,$25,$25
 dta $00,$0C,$25,$0C,$00,$0C,$25,$0C
 dta $0A,$16,$25,$16,$0A,$25,$0A,$25
 dta $00,$0C,$25,$0C,$00,$0C,$25,$0C
 dta $00,$0C,$25,$0C,$07,$05,$25,$25
 dta $00,$0C,$25,$0C,$00,$0C,$25,$0C
 dta $00,$0C,$25,$0C,$07,$25,$03,$25
 dta $30,$30,$31,$30,$30,$31,$2D,$2D
 dta $31,$2B,$2B,$31,$27,$31,$27,$31
 dta $30,$30,$30,$30,$30,$30,$2D,$2D
 dta $2D,$2A,$2A,$2A,$27,$27,$27,$27
 dta $18,$1F,$18,$1D,$1F,$18,$22,$1F
 dta $18,$1D,$1F,$18,$24,$1F,$22,$24
 dta $18,$1F,$22,$1D,$1F,$18,$22,$1F
 dta $18,$1D,$1B,$1F,$1A,$1D,$16,$1A
 dta $18,$1F,$18,$1D,$1F,$18,$22,$1F
 dta $18,$1D,$1F,$18,$24,$1F,$22,$24
 dta $18,$1F,$22,$1D,$1F,$18,$22,$1F
 dta $18,$1D,$1B,$18,$1A,$1B,$16,$1A
 dta $ff

kanal2 dta $00,$0C,$00,$0C,$00,$0C,$00,$0C
 dta $08,$14,$08,$14,$05,$11,$05,$11
 dta $00,$0C,$00,$0C,$00,$0C,$00,$0C
 dta $08,$14,$08,$14,$05,$11,$05,$07
 dta $00,$0C,$25,$0C,$00,$0C,$25,$0C
 dta $08,$14,$25,$14,$05,$11,$25,$25
 dta $00,$0C,$25,$0C,$00,$0C,$25,$0C
 dta $08,$14,$25,$14,$05,$25,$05,$25
 dta $1F,$0C,$1F,$0C,$1D,$1F,$00,$18
 dta $03,$18,$1B,$18,$03,$18,$1B,$18
 dta $1F,$14,$1F,$14,$1D,$1F,$08,$18
 dta $05,$18,$1B,$18,$1F,$1D,$1B,$1D
 dta $1F,$0C,$1F,$0C,$1D,$1B,$25,$18
 dta $03,$18,$1B,$18,$03,$18,$1F,$18
 dta $1F,$14,$1F,$14,$1D,$1B,$08,$18
 dta $05,$18,$1B,$1D,$1F,$1D,$1B,$1A
 dta $18,$0F,$18,$0F,$16,$18,$03,$13
 dta $05,$18,$1B,$1D,$1F,$1D,$1B,$1D
 dta $18,$0C,$1A,$0C,$1B,$18,$00,$1F
 dta $0A,$1D,$1B,$1D,$1F,$1D,$1B,$1D
 dta $18,$0F,$18,$0F,$16,$18,$03,$13
 dta $05,$1D,$1B,$1D,$1F,$1D,$1B,$1A
 dta $18,$0C,$18,$1A,$1B,$18,$00,$1F
 dta $0A,$1F,$1D,$1B,$1D,$1B,$1A,$16
 dta $00,$0C,$00,$0C,$00,$0C,$00,$0C
 dta $00,$0C,$00,$0C,$07,$05,$03,$05
 dta $00,$0C,$00,$0C,$00,$0C,$00,$0C
 dta $00,$0C,$00,$0C,$07,$05,$03,$02
 dta $30,$30,$30,$30,$30,$30,$2D,$2D
 dta $2D,$2B,$2B,$2A,$27,$27,$27,$27
 dta $30,$30,$31,$30,$30,$31,$2D,$2D
 dta $31,$2A,$2A,$31,$27,$31,$27,$31
 dta $18,$1F,$31,$1D,$1F,$31,$22,$1F
 dta $31,$1D,$1F,$31,$24,$31,$22,$31
 dta $18,$1F,$31,$1D,$1F,$31,$22,$1F
 dta $31,$1D,$1B,$31,$1A,$31,$16,$31
 dta $18,$1F,$31,$1D,$1F,$31,$22,$1F
 dta $31,$1D,$1F,$31,$24,$31,$22,$31
 dta $18,$1F,$31,$1D,$1F,$31,$22,$1F
 dta $31,$1D,$1B,$31,$1A,$31,$16,$31
 dta $ff

 org $2e0
 dta a(run_adr)

 

 

for Atari PLUG IN DATA RECORDER !!! or use Altirra.

temp.obx

  • Like 1

Share this post


Link to post
Share on other sites

*deleted*

 

Argh. Ok, I should read before writing bullshit...

Edited by skr

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...