Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #4720 > unrolled thread

code golf (do my homework)

Started byqkumba <peter.ferrie@gmail.com>
First post2018-08-27 09:08 -0700
Last post2018-08-29 06:50 -0700
Articles 16 — 7 participants

Back to article view | Back to comp.sys.apple2.programmer


Contents

  code golf (do my homework) qkumba <peter.ferrie@gmail.com> - 2018-08-27 09:08 -0700
    Re: code golf (do my homework) Marco Verpelli <mverpelli@libero.it> - 2018-08-27 09:35 -0700
      Re: code golf (do my homework) qkumba <peter.ferrie@gmail.com> - 2018-08-27 09:52 -0700
    Re: code golf (do my homework) James Davis <JPD.Enterprises@outlook.com> - 2018-08-27 12:30 -0700
    Re: code golf (do my homework) John Brooks <jbrooks@blueshiftinc.com> - 2018-08-27 14:36 -0700
      Re: code golf (do my homework) qkumba <peter.ferrie@gmail.com> - 2018-08-27 17:53 -0700
        Re: code golf (do my homework) John Brooks <jbrooks@blueshiftinc.com> - 2018-08-27 19:28 -0700
          Re: code golf (do my homework) Antoine Vignau <antoine.vignau@laposte.net> - 2018-08-27 20:14 -0700
            Re: code golf (do my homework) Antoine Vignau <antoine.vignau@laposte.net> - 2018-08-27 20:15 -0700
              Re: code golf (do my homework) qkumba <peter.ferrie@gmail.com> - 2018-08-28 11:29 -0700
                Re: code golf (do my homework) Antoine Vignau <antoine.vignau@laposte.net> - 2018-08-28 13:37 -0700
                Re: code golf (do my homework) Antoine Vignau <antoine.vignau@laposte.net> - 2018-08-28 13:41 -0700
                  Re: code golf (do my homework) Antoine Vignau <antoine.vignau@laposte.net> - 2018-08-28 13:48 -0700
                Re: code golf (do my homework) awanderin <awanderin@gmail.com> - 2018-08-30 20:36 -0600
                  Re: code golf (do my homework) Antoine Vignau <antoine.vignau@laposte.net> - 2018-09-02 12:21 -0700
    Re: code golf (do my homework) Tom Porter <laseractiveguy@gmail.com> - 2018-08-29 06:50 -0700

#4720 — code golf (do my homework)

Fromqkumba <peter.ferrie@gmail.com>
Date2018-08-27 09:08 -0700
Subjectcode golf (do my homework)
Message-ID<454bbaa3-4305-4913-8f0a-e7976f4ec447@googlegroups.com>
4am asked me for two routines:
1) detect 128kb
2) detect a joystick.

Here's my 128kb detection:
lda #$18 ;clc
sta $c005
sta flag
sta $c004
flag: sec

The intention is that carry is clear if 128kb is present.
Note that this doesn't work in Virtual II.
Any issues with it?  Any smaller way?

I don't have a good joystick detection yet.  Suggestions welcome.

[toc] | [next] | [standalone]


#4721

FromMarco Verpelli <mverpelli@libero.it>
Date2018-08-27 09:35 -0700
Message-ID<9ad83ae0-3be1-4b47-8f62-8888c944e470@googlegroups.com>
In reply to#4720
> I don't have a good joystick detection yet.  Suggestions welcome.

Prince of Persia: look at lines 1225-1270

https://github.com/jmechner/Prince-of-Persia-Apple-II/blob/master/01%20POP%20Source/Source/GRAFIX.S

Marco

[toc] | [prev] | [next] | [standalone]


#4722

Fromqkumba <peter.ferrie@gmail.com>
Date2018-08-27 09:52 -0700
Message-ID<715703b8-8781-4d47-ad1a-13a87fc836f4@googlegroups.com>
In reply to#4721
Thanks, that looks okay.

Back to the 128kb detection, I seem to recall a thread which mentioned where $c005 writes go when the 80 column card isn't the extended type, but I can't find it.  I wonder if my code even works.

[toc] | [prev] | [next] | [standalone]


#4724

FromJames Davis <JPD.Enterprises@outlook.com>
Date2018-08-27 12:30 -0700
Message-ID<34e72c83-dd93-4aa8-a049-eb3edd538529@googlegroups.com>
In reply to#4720
On Monday, August 27, 2018 at 9:08:59 AM UTC-7, qkumba wrote:
> 4am asked me for two routines:
> 1) detect 128kb
> 2) detect a joystick.
> 
> Here's my 128kb detection:
> lda #$18 ;clc
> sta $c005
> sta flag
> sta $c004
> flag: sec
> 
> The intention is that carry is clear if 128kb is present.
> Note that this doesn't work in Virtual II.
> Any issues with it?  Any smaller way?
> 
> I don't have a good joystick detection yet.  Suggestions welcome.

A plugged in joy stick would probably be centered and, when triggered, timeout near 128 [max.(256) > (return value) > min.(0)].  A pair of paddles might not.--They could be anywhere from max. to min.--Instruct user to center them, first.  Nothing there would be max. or min. (depending on paddle number {PDL#}) and not in between.

If the extra 64K is not there, a write, read, and compare of a range of values to and from it will fail.  Otherwise, the compare should detect equivalency of all values written then re-read.

[toc] | [prev] | [next] | [standalone]


#4725

FromJohn Brooks <jbrooks@blueshiftinc.com>
Date2018-08-27 14:36 -0700
Message-ID<73c8e19c-edca-49dd-bccb-fe13c041bece@googlegroups.com>
In reply to#4720
On Monday, August 27, 2018 at 9:08:59 AM UTC-7, qkumba wrote:
> 4am asked me for two routines:
> 1) detect 128kb
> 2) detect a joystick.
> 
> Here's my 128kb detection:
> lda #$18 ;clc
> sta $c005
> sta flag
> sta $c004
> flag: sec
> 
> The intention is that carry is clear if 128kb is present.
> Note that this doesn't work in Virtual II.
> Any issues with it?  Any smaller way?
> 
> I don't have a good joystick detection yet.  Suggestions welcome.

ProDOS detects 128KB RAM by copying this code to ZP $0080 and running it:

		lda	#$ee		; first	try storing in aux mem
		sta	$c005		; write	to aux while on	main zp
		sta	$c003		; set to read aux ram
		sta	$c00		; check	for sparse mem mapping
		sta	$800
		lda	$c00		; see if sparse	memory -same value 
		cmp	#$ee		; 1k away 
		bne	noaux
		asl	$c00		; may be sparse	mem so change value 
		asl	a		; & see	what happens  
		cmp	$c00
		bne	noaux
		cmp	$800
		bne	auxmem
noaux		sec			; sparse mapping so no aux mem
		bcs	back
auxmem		clc			; there	is aux mem
back		sta	$c004		; switch  back to write	main ram
		sta	$c002		; switch back main ram read
		bcs	not128		; branch if not	128k
		lda	apple		; else update identity of machine.
		ora	#$30		; indicate 128k	present.
		sta	apple


not128		lda	look+1		; futs with pointer for	apple test.
		sec
		sbc	#$05		; should result	in $fb if zpage	is ok. 
		sta	look+1
		bcs	@1		; (to the clc)
		dec	look
@1		clc
		rts

-JB
@JBrooksBSI

[toc] | [prev] | [next] | [standalone]


#4727

Fromqkumba <peter.ferrie@gmail.com>
Date2018-08-27 17:53 -0700
Message-ID<6a250c8b-92aa-46fd-a7de-eb165b884dcb@googlegroups.com>
In reply to#4725
Yes, I am well aware of what ProDOS does, but my question remains:
if a standard 80-column card is present, does $C005 cause writes to go to outer-space, or does it go to main memory instead?
i.e. do I really need to read it back via $C003?

[toc] | [prev] | [next] | [standalone]


#4728

FromJohn Brooks <jbrooks@blueshiftinc.com>
Date2018-08-27 19:28 -0700
Message-ID<eaa745c1-56b9-4473-aa44-330e455fc3b2@googlegroups.com>
In reply to#4727
On Monday, August 27, 2018 at 5:53:47 PM UTC-7, qkumba wrote:
> Yes, I am well aware of what ProDOS does, but my question remains:
> if a standard 80-column card is present, does $C005 cause writes to go to outer-space, or does it go to main memory instead? 

Neither. The write goes to aux mem and lands in the 1KB repeating throughout aux mem. This is why ProDOS reads aux mem at $800 and $C00 to see if there is 64k of aux or 1K (or no aux at all)


> i.e. do I really need to read it back via $C003?

Yes.


-JB
@JBrooksBSI

[toc] | [prev] | [next] | [standalone]


#4729

FromAntoine Vignau <antoine.vignau@laposte.net>
Date2018-08-27 20:14 -0700
Message-ID<6237b84d-1d18-4f5e-8434-5ced583bcfb3@googlegroups.com>
In reply to#4728
Lode Runner has a small and clever joystick detection,
av

[toc] | [prev] | [next] | [standalone]


#4730

FromAntoine Vignau <antoine.vignau@laposte.net>
Date2018-08-27 20:15 -0700
Message-ID<d8e0b8d4-bc6c-4e76-8d18-1059a6c76300@googlegroups.com>
In reply to#4729
And for 128k, use MACHID from the ProDOS global page,
av

[toc] | [prev] | [next] | [standalone]


#4733

Fromqkumba <peter.ferrie@gmail.com>
Date2018-08-28 11:29 -0700
Message-ID<4f907f75-da07-4e29-b030-b79027285e04@googlegroups.com>
In reply to#4730
> And for 128k, use MACHID from the ProDOS global page,

We are expecting ProDOS to not be present at the time.
Hence the need to implement these things ourselves.
It looks like the ProDOS detection is what I need.
I'll check Lode Runner next.
Thanks.

[toc] | [prev] | [next] | [standalone]


#4735

FromAntoine Vignau <antoine.vignau@laposte.net>
Date2018-08-28 13:37 -0700
Message-ID<db87c588-5e80-4143-8e42-4459947247b0@googlegroups.com>
In reply to#4733
For 128k:

look		equ	$0a		; must go at $000a!!
apple		equ	$0c

tst128		equ	$80		; use zpage for	this routine 
strt128		sta	apple		; save accumulated value.
		bpl	not128		; branch if sure it's less than 128k.


		lda	#$ee		; first	try storing in aux mem
		sta	$c005		; write	to aux while on	main zp
		sta	$c003		; set to read aux ram
		sta	$c00		; check	for sparse mem mapping
		sta	$800
		lda	$c00		; see if sparse	memory -same value 
		cmp	#$ee		; 1k away 
		bne	noaux
		asl	$c00		; may be sparse	mem so change value 
		asl	a		; & see	what happens  
		cmp	$c00
		bne	noaux
		cmp	$800
		bne	auxmem
noaux		sec			; sparse mapping so no aux mem
		bcs	back
auxmem		clc			; there	is aux mem
back		sta	$c004		; switch  back to write	main ram
		sta	$c002		; switch back main ram read
		bcs	not128		; branch if not	128k
		lda	apple		; else update identity of machine.
		ora	#$30		; indicate 128k	present.
		sta	apple


not128		lda	look+1		; futs with pointer for	apple test.
		sec
		sbc	#$05		; should result	in $fb if zpage	is ok. 
		sta	look+1
		bcs	@1		; (to the clc)
		dec	look
@1		clc
		rts
end128		equ	*-strt128	; byte count for routine move to zpage.

[toc] | [prev] | [next] | [standalone]


#4736

FromAntoine Vignau <antoine.vignau@laposte.net>
Date2018-08-28 13:41 -0700
Message-ID<f1e37af6-3434-45a1-bac4-75879eb64147@googlegroups.com>
In reply to#4733
Lode Runner, the joystick detection:

PADDL0 = $C064
PADDL1 = $C065
PTRIG = $C070

L87A2       LDA   PTRIG                                                         
            LDX   #$10                                                          
L87A7       LDA   PADDL0                                                        
            ORA   PADDL1                                                        
            BPL   L87B9                                                         
            DEY                                                                 
            BNE   L87A7                                                         
            DEX                                                                 
            BNE   L87A7                                                         
            LDA   #$CB       ; K                                                
            STA   fgINPUT                                                       
L87B9       RTS                                                                 

You read 6502 code better than me, so you'll see that it sets the input to keyboard "K" if no joystick is detected,

av

[toc] | [prev] | [next] | [standalone]


#4737

FromAntoine Vignau <antoine.vignau@laposte.net>
Date2018-08-28 13:48 -0700
Message-ID<0eac0558-8e85-4273-91d6-09fd79eb6e7b@googlegroups.com>
In reply to#4736
On Tuesday, August 28, 2018 at 10:41:28 PM UTC+2, Antoine Vignau wrote:
> Lode Runner, the joystick detection:
> 
> PADDL0 = $C064
> PADDL1 = $C065
> PTRIG = $C070
> 
> L87A2       LDA   PTRIG                                                         
>             LDX   #$10                                                          
> L87A7       LDA   PADDL0                                                        
>             ORA   PADDL1                                                        
>             BPL   L87B9                                                         
>             DEY                                                                 
>             BNE   L87A7                                                         
>             DEX                                                                 
>             BNE   L87A7                                                         
>             LDA   #$CB       ; K                                                
>             STA   fgINPUT                                                       
> L87B9       RTS                                                                 
> 
> You read 6502 code better than me, so you'll see that it sets the input to keyboard "K" if no joystick is detected,
> 
> av

and Y is set to $#$0B by the move arm routine at $65D,
av

[toc] | [prev] | [next] | [standalone]


#4740

Fromawanderin <awanderin@gmail.com>
Date2018-08-30 20:36 -0600
Message-ID<yubsh2vs1nw.fsf@gmail.com>
In reply to#4733
qkumba <peter.ferrie@gmail.com> writes:

>> And for 128k, use MACHID from the ProDOS global page,
>
> We are expecting ProDOS to not be present at the time.
> Hence the need to implement these things ourselves.
> It looks like the ProDOS detection is what I need.
> I'll check Lode Runner next.
> Thanks.

Apple's Misc Tech-Note #002 has machine-ID code and includes this
aux-RAM checker:

------------------------------------------------------------
rdmainram  equ $C002        ;read main ram
rdcardram  equ $C003        ;read aux ram
wrmainram  equ $C004        ;write main ram
wrcardram  equ $C005        ;write aux ram

[...]

*  This is the routine run in the safe area not affected
*  by bank-switching the main and aux RAM.

start      lda #test4       ;yet another test byte
           sta wrcardram    ;write to aux while on main zero page
           sta rdcardram    ;read aux ram as well
           sta begpage2     ;check for sparse memory mapping
           lda begsprse     ;if sparse, these will be the same
           cmp #test4       ;value since they're 1K apart
           bne auxmem       ;yup, there's 128K!
           asl begsprse     ;may have been lucky so we'll
           lda begpage2     ;change the value and see what happens
           cmp begsprse
           bne auxmem
           sec              ;oops, no auxiliary memory
           bcs goback
auxmem     clc
goback     sta wrmainram    ;write main RAM
           sta rdmainram    ;read main RAM
           jmp back         ;continue with program in main mem
done       nop              ;end of relocated program marker
------------------------------------------------------------

-- 
--
Jerry    awanderin at gmail dot com

[toc] | [prev] | [next] | [standalone]


#4741

FromAntoine Vignau <antoine.vignau@laposte.net>
Date2018-09-02 12:21 -0700
Message-ID<147a9e98-8155-4253-9d4f-355789aa05b0@googlegroups.com>
In reply to#4740
The code above is the one used in ProDOS but with less labels,
av

[toc] | [prev] | [next] | [standalone]


#4739

FromTom Porter <laseractiveguy@gmail.com>
Date2018-08-29 06:50 -0700
Message-ID<6008fe80-0fe5-475b-8a70-5685afec68dd@googlegroups.com>
In reply to#4720
What I do is include Beagle-Brothers Aux-Mem-Check code whenever I want to do this... however I am sure you are going on size, and this is a little larger, but it does check all conditions, II+, IIE with no card, with card and with 128kb... I am sure you can strip it down to its core and only check for 128kb.


0200-   08          PHP
0201-   78          SEI
0202-   AD 00 E0    LDA   $E000
0205-   85 1A       STA   $1A
0207-   AD 00 D0    LDA   $D000
020A-   85 1B       STA   $1B
020C-   AD 00 D4    LDA   $D400
020F-   85 1C       STA   $1C
0211-   AD 00 D8    LDA   $D800
0214-   85 1D       STA   $1D
0216-   AD 81 C0    LDA   $C081    rw:ROMIN
0219-   AD 81 C0    LDA   $C081    rw:ROMIN
021C-   AD B3 FB    LDA   $FBB3    F8ROM:VERSION
021F-   C9 06       CMP   #$06
0221-   D0 3A       BNE   $025D
0223-   AD 17 C0    LDA   $C017    r:RDC3ROM
0226-   30 32       BMI   $025A
0228-   AD 13 C0    LDA   $C013    r:RDRAMRD
022B-   30 27       BMI   $0254
022D-   AD 16 C0    LDA   $C016    r:RDALTZP
0230-   30 22       BMI   $0254
0232-   A0 28       LDY   #$28
0234-   BE A3 02    LDX   $02A3,Y
0237-   B9 00 01    LDA   $0100,Y
023A-   99 A3 02    STA   $02A3,Y
023D-   8A          TXA
023E-   99 00 01    STA   $0100,Y
0241-   88          DEY
0242-   10 F0       BPL   $0234
0244-   4C 00 01    JMP   $0100
0247-   A0 28       LDY   #$28
0249-   B9 A3 02    LDA   $02A3,Y
024C-   99 00 01    STA   $0100,Y
024F-   88          DEY
0250-   10 F7       BPL   $0249
0252-   B0 03       BCS   $0257
0254-   A9 80       LDA   #$80
0256-   2C A9 40    BIT   $40A9
0259-   2C A9 20    BIT   $20A9
025C-   2C A9 00    BIT   $00A9
025F-   85 06       STA   $06
0261-   AD 00 E0    LDA   $E000
0264-   C5 1A       CMP   $1A
0266-   D0 15       BNE   $027D
0268-   AD 00 D0    LDA   $D000
026B-   C5 1B       CMP   $1B
026D-   D0 0E       BNE   $027D
026F-   AD 00 D4    LDA   $D400
0272-   C5 1C       CMP   $1C
0274-   D0 07       BNE   $027D
0276-   AD 00 D8    LDA   $D800
0279-   C5 1D       CMP   $1D
027B-   F0 22       BEQ   $029F
027D-   AD 88 C0    LDA   $C088
0280-   AD 00 E0    LDA   $E000
0283-   C5 1A       CMP   $1A
0285-   D0 15       BNE   $029C
0287-   AD 00 D0    LDA   $D000
028A-   C5 1B       CMP   $1B
028C-   D0 0E       BNE   $029C
028E-   AD 00 D4    LDA   $D400
0291-   C5 1C       CMP   $1C
0293-   D0 07       BNE   $029C
0295-   AD 00 D8    LDA   $D800
0298-   C5 1D       CMP   $1D
029A-   F0 03       BEQ   $029F
029C-   AD 80 C0    LDA   $C080
029F-   28          PLP
02A0-   A5 06       LDA   $06
02A2-   60          RTS
02A3-   A9 EE       LDA   #$EE
02A5-   8D 05 C0    STA   $C005    w:WRCARDRAM
02A8-   8D 03 C0    STA   $C003    w:RDCARDRAM
02AB-   8D 00 08    STA   $0800
02AE-   AD 00 0C    LDA   $0C00
02B1-   C9 EE       CMP   #$EE
02B3-   D0 0D       BNE   $02C2
02B5-   0E 00 0C    ASL   $0C00
02B8-   AD 00 08    LDA   $0800
02BB-   CD 00 0C    CMP   $0C00
02BE-   D0 02       BNE   $02C2
02C0-   38          SEC
02C1-   90 18       BCC   $02DB
02C3-   8D 04 C0    STA   $C004    w:WRMAINRAM
02C6-   8D 02 C0    STA   $C002    w:RDMAINRAM
02C9-   4C 47 02    JMP   $0247

	10  PRINT  CHR$ (4)"BRUN AUX.MEM.CHECK"
 	20  A=PEEK (6)

	= 0 not an IIE
	=32 IIE with no cards,  
	=64 IIE with 80col only card)
	=128 IIE with 128kb

[toc] | [prev] | [standalone]


Back to top | Article view | comp.sys.apple2.programmer


csiph-web