NuY Posted February 10, 2009 Share Posted February 10, 2009 (edited) This one's a bit beyond me Attached to this post is a Basic program which refuses to work under Basic revisions B and C; it does bizarre things with the variable name tables with some machine code instructions hidden away in the variable space. Would anyone be able to either: 1. Fix the program in Basic so that it can run under revision C; 2. Make it into a binary file that also includes Basic revision A in the binary, thereby solving the problem? The program is called Ski, and is taken from Compute!'s First Book of Atari Games. I should add, it works fine under emulation with the Basic A cartridge attached under OS B. Cheers! ski.bas Edited February 10, 2009 by NuY Quote Link to comment Share on other sites More sharing options...
thorfdbg Posted February 10, 2009 Share Posted February 10, 2009 This one's a bit beyond me Attached to this post is a Basic program which refuses to work under Basic revisions B and C; it does bizarre things with the variable name tables with some machine code instructions hidden away in the variable space. Would anyone be able to either: 1. Fix the program in Basic so that it can run under revision C; 2. Make it into a binary file that also includes Basic revision A in the binary, thereby solving the problem? The program is called Ski, and is taken from Compute!'s First Book of Atari Games. I should add, it works fine under emulation with the Basic A cartridge attached under OS B. Cheers! Most likely, the tokenized version is corrupt - what I can send you is an untokenizer program that will hopefully recover the source from the .BAS file. ENTERing the resulting output of the program should then hopefully restore it. Please contact me at thor at math dot tu dash berlin dot de. So long, Quote Link to comment Share on other sites More sharing options...
NuY Posted February 10, 2009 Author Share Posted February 10, 2009 Nothing to do with the tokenising, this is a program I've entered myself from the book. The program is designed to mess about with the var table, but it uses something in Basic rev A that isn't in rev B or C. The program loads in fine under any of the revisions, so doesn't need fixing in that sense; the program actually needs modifying to work under Basic C. Quote Link to comment Share on other sites More sharing options...
thorfdbg Posted February 11, 2009 Share Posted February 11, 2009 Nothing to do with the tokenising, this is a program I've entered myself from the book. The program is designed to mess about with the var table, but it uses something in Basic rev A that isn't in rev B or C. The program loads in fine under any of the revisions, so doesn't need fixing in that sense; the program actually needs modifying to work under Basic C. In that case, the program likely depends on the precise layout of the vtable. If it was a type-in, my suggestion is to LIST it back to disk, then ENTER it, just to recreate the vtable. This should hopefully bring all variables back to their canonical order. If the offsets aren't right after that, the only hope is to adjust the program and fixup the offsets. Greetings, Thomas Quote Link to comment Share on other sites More sharing options...
NuY Posted February 11, 2009 Author Share Posted February 11, 2009 It's actually a machine code routine stored in the varname space by a previous program, and then that program is removed from memory, but the machine code stays resident. The game listing is then ENTER'd in, and the resulting program including the machine code is then saved out as a Basic prog. Strings are dimensioned to 1 char size at the start of the program, and then a USR call is made to expand this to the size of the MC routine, with A$ being the placeholder for the MC. Various calls are then made to USR(ADR(A$)) throughout the program for (I assume) scrolling and such. It's the expansion of the vartable that causes this program not to work under any Basic revision other than A. It's not an OS issue, as it works fine under emulation with XL/XE OS, and the Basic rev A cartridge mounted, but I don't know enough about MC or the differences between Basic revisions to be able to fix it. I have the original listings LISTed to disk, but building the program up under rev C results in the program just hanging at the initial USR call. Quote Link to comment Share on other sites More sharing options...
Rybags Posted February 11, 2009 Share Posted February 11, 2009 Just change it to store the Asm code in a file. Read the file in with the main program to a string. That's assuming the routine is relocatable... if it isn't, then it probably only works with a specific DOS version (size) too. Quote Link to comment Share on other sites More sharing options...
NuY Posted February 11, 2009 Author Share Posted February 11, 2009 Didn't think of that - I was getting hung up on the fact that it messes with the var table in the MC. It seems to work under most DOS versions; I tried it under SpartaDOS 3.2 and Atari DOS emulated with the Basic A cart, and it was fine. The USR calls are calculated relative to the start of the vartable, and it's working out which USR call messes with it, and which call invokes the VBI. I think relocating the code may be doable, but another problem is that it uses some PMGs in strings as well as the MC, and I think the MC relocates the PM string so that it doesn't cross a 4k boundary, and subsequently redimensions the string to the correct size. I've disassembled the code using DIS6502 below, and also the initial setup program to put the code in the vartable, as well as the bits of Basic where the code is called from in the main program: Loader prog: 0 REM ÌÏÁÄÅÒ ÆÏÒ §ÓËɧ ÂÁÓÉà ÒÁÍ 10 ? "JUST A MOMENT":DIM A$(746):A=1:B=0:C=20:FOR D=0 TO 36:GOSUB 70:NEXT D:C=6:GOSUB 70 20 IF B<>73882 THEN ? "CHECK ALL DATA LINES":END 25 STOP 30 VNTD=PEEK(132)+256*PEEK(133) 40 A=USR(ADR(A$),746) 50 A=USR(ADR(A$)+22,VNTD+1,ADR(A$),746) 60 GOTO 1000 70 E=0:FOR F=1 TO C:READ G:E=E+G:B=B+G:A$(A,A)=CHR$(G):A=A+1:NEXT F 80 READ F:IF F<>E THEN ? "CHECK DATA STATEMENTS AT LINE ";100+D*10:END 90 RETURN Main game: 100 DIM SCREEN$(1),PM$(1) 101 DIM LEFT$(20),CENTER$(20),RIGHT$(20),CURR$(20),CRASH$(20),ERASE$(20),DIR(8),SCR(4),DLIST$(1) 102 DIM T$(20),TOPLINE$(20):GOTO 130 110 REM ª ÓËÉ ª LINE 100 MUST BE TYPEDIN FIRST!!! 120 HI=INT(A/256):LO=A-HI*256:RETURN 125 POKE 66,1:FOR W=1 TO 10:POKE 53279,0:POKE 53279,8:NEXT W:POKE 66,0:RETURN 130 GOSUB 790:REM Initialization routines --- 790 REM ÉÎÉÔÉÁÌÉÚÁÔÉÏÎ 800 GRAPHICS 17:HILO=120:POKE 53248,0:POKE 0,0 810 SETCOLOR 4,0,12:SETCOLOR 1,12,8:SETCOLOR 2,9,6:SETCOLOR 0,15,4 820 P0PF=53252:HITCLR=53278:POKE HITCLR,0 830 SCRBASE=PEEK(106)-16:REM 4K BOUNDARY 840 PMBASE=SCRBASE-8:REM 2K BOUNDARY,DOUBLE-LINE RES 850 CHBASE=PMBASE:REM FILL UP OFFSET WITH CHARACTERS 870 VNTD=PEEK(132)+256*PEEK(133) 880 A=USR(VNTD+90,ADR(SCREEN$),4097,4097,SCRBASE*256) 890 A=USR(VNTD+90,ADR(PM$),2049,2049,PMBASE*256) 900 A=USR(VNTD+90,ADR(DLIST$),40,40,VNTD+134) 910 CHSET=CHBASE*256 920 A=USR(VNTD+23,CHSET,VNTD+174,120):A=USR(VNTD+23,CHSET+128,57472,344):A=USR(VNTD+23,CHSET+208,VNTD+294,48) 930 A=VNTD+377:GOSUB 120:POKE VNTD+368,HI:POKE VNTD+370,LO 940 A=USR(VNTD+23,1649,VNTD+494,103) 950 Z=USR(VNTD+483):REM DISABLE VBLANK ASM listing: DSKINV = $E453 CIOV = $E456 SIOV = $E459 SETVBV = $E45C SYSVBV = $E45F XITVBV = $E462 SIOINV = $E465 SENDEV = $E468 INTINV = $E46B CIOINV = $E46E SELFSV = $E471 WARMSV = $E474 COLDSV = $E477 RBLOKV = $E47A CSOPIV = $E47D PUPDIV = $E480 SELFTSV = $E483 PENTV = $E486 PHUNLV = $E489 PHINIV = $E48C GPDVV = $E48F ; ; Code equates ; L0082 = $0082 L008A = $008A L008C = $008C L008D = $008D L0099 = $0099 L009A = $009A L009B = $009B L009C = $009C L009D = $009D L00CB = $00CB L00CC = $00CC L00CD = $00CD L00CE = $00CE L00CF = $00CF L00D0 = $00D0 L00D1 = $00D1 L0662 = $0662 L0663 = $0663 L0664 = $0664 L0671 = $0671 L067B = $067B L068B = $068B L1010 = $1010 L180A = $180A L1859 = $1859 L3E3E = $3E3E L5E6A = $5E6A L8000 = $8000 L844A = $844A L9A18 = $9A18 L9A7F = $9A7F LA881 = $A881 LA8E3 = $A8E3 LA8FD = $A8FD LA94C = $A94C LAC28 = $AC28 ; ; Start of code ; *= $1635 ; pla ; 68 pla ; 68 tax ; AA pla ; 68 tay ; A8 txa ; 8A ldx #$86 ; A2 86 jmp LA881 ; 4C 81 A8 pla ; 68 pla ; 68 tax ; AA pla ; 68 tay ; A8 txa ; 8A ldx #$86 ; A2 86 jmp LA8FD ; 4C FD A8 pla ; 68 ldx #$03 ; A2 03 L164E: pla ; 68 sta L0099,X ; 95 99 dex ; CA bpl L164E ; 10 FA sec ; 38 lda L009B ; A5 9B sbc L0099 ; E5 99 lda L009C ; A5 9C sbc L009A ; E5 9A pla ; 68 tax ; AA bcc L1671 ; 90 10 clc ; 18 adc L009A ; 65 9A sta L009A ; 85 9A txa ; 8A adc L009C ; 65 9C sta L009C ; 85 9C inx ; E8 pla ; 68 tay ; A8 jmp LA8E3 ; 4C E3 A8 L1671: inx ; E8 pla ; 68 tay ; A8 adc L0099 ; 65 99 sta L0099 ; 85 99 bcs L167C ; B0 02 dec L009A ; C6 9A L167C: tya ; 98 clc ; 18 adc L009B ; 65 9B sta L009B ; 85 9B bcs L1686 ; B0 02 dec L009C ; C6 9C L1686: tya ; 98 eor #$FF ; 49 FF tay ; A8 iny ; C8 jmp LA94C ; 4C 4C A9 pla ; 68 pla ; 68 pla ; 68 ldy #$04 ; A0 04 L1693: iny ; C8 lda (L008A),Y ; B1 8A cmp #$3C ; C9 3C bne L1693 ; D0 F9 iny ; C8 iny ; C8 iny ; C8 lda (L008A),Y ; B1 8A jsr LAC28 ; 20 28 AC ldy #$07 ; A0 07 L16A4: pla ; 68 sta (L009D),Y ; 91 9D dey ; 88 cpy #$02 ; C0 02 bne L16A4 ; D0 F8 sec ; 38 tax ; AA pla ; 68 sbc L008C ; E5 8C sta (L009D),Y ; 91 9D iny ; C8 txa ; 8A sbc L008D ; E5 8D sta (L009D),Y ; 91 9D rts ; 60 bvs L172C ; 70 70 bvs L1704 ; 70 46 .byte $9B,$22 ror RTCLOK+2 ; 66 14 bcc L16EA ; 90 26 rol ICPTLZ ; 26 26 rol ICPTLZ ; 26 26 rol ICPTLZ ; 26 26 rol ICPTLZ ; 26 26 rol ICPTLZ ; 26 26 rol ICPTLZ ; 26 26 rol ICPTLZ ; 26 26 rol ICPTLZ ; 26 26 rol ICPTLZ ; 26 26 rol TRAMSZ ; 26 06 eor (L0082,X) ; 41 82 ora #$00 ; 09 00 .byte $00,$00 ora $00,X ; 15 00 .byte $00,$00,$00,$00,$00,$00,$00,$00 .byte $00,$00 L16EA: .byte $00 asl APPMHI ; 06 0E .byte $1C clc ; 18 jsr L8000 ; 20 00 80 .byte $00,$00,$00,$00,$00,$00,$00,$00 .byte $00,$00,$00,$00,$00,$00,$00,$00 .byte $00,$00 L1704: .byte $00,$00,$00,$00,$00,$00,$00,$00 L170C: .byte $00,$00,$00,$00,$00,$00 cpy #$C0 ; C0 C0 .byte $DC,$14,$1C,$07 ora CMCMD ; 05 07 .byte $00,$00 clc ; 18 .byte $34 bit L183C ; 2C 3C 18 .byte $00 bpl L175C ; 10 38 sec ; 38 .byte $7C,$7C inc L1010,X ; FE 10 10 php ; 08 .byte $1C L172C: rol L3E3E,X ; 3E 3E 3E php ; 08 php ; 08 .byte $00,$00 sec ; 38 lsr L5E6A,X ; 5E 6A 5E .byte $74 sec ; 38 .byte $00,$00,$77 eor ENDPT+1 ; 45 75 ora DELTAC,X ; 15 77 .byte $00,$00 php ; 08 clc ; 18 sec ; 38 sei ; 78 php ; 08 php ; 08 php ; 08 php ; 08 .byte $00,$00,$00 bmi L17A7 ; 30 58 sec ; 38 bpl L170C ; 10 BA inc L1859,X ; FE 59 18 .byte $9C,$52 and (POKMSK,X) ; 21 10 php ; 08 .byte $00,$00 L175C: .byte $00,$0C,$1A,$1C php ; 08 eor L9A7F,X ; 5D 7F 9A clc ; 18 and L844A,Y ; 39 4A 84 php ; 08 bpl L176B ; 10 00 L176B: .byte $00 clc ; 18 .byte $3C,$3C clc ; 18 clc ; 18 .byte $3C tsx ; BA eor L9A18,Y ; 59 18 9A tax ; AA dec SOUNDR ; C6 41 eor (NGFLAG,X) ; 41 01 .byte $12 bit ZCHAIN ; 24 4A lda (RTCLOK,X) ; A1 12 .byte $9C eor L180A ; 4D 0A 18 clc ; 18 .byte $00,$00,$00,$00,$00 lda #$00 ; A9 00 sta $00 ; 85 00 lda #$01 ; A9 01 sta L0663 ; 8D 63 06 lda #$08 ; A9 08 sta L0662 ; 8D 62 06 pla ; 68 pla ; 68 sta CMCMD ; 85 07 pla ; 68 sta TRAMSZ ; 85 06 pla ; 68 pla ; 68 sta NGFLAG ; 85 01 ldx #$0A ; A2 0A ldy #$75 ; A0 75 L17A7: lda #$07 ; A9 07 jsr SETVBV ; 20 5C E4 rts ; 60 cld ; D8 lda P0PF ; AD 04 D0 beq L17B7 ; F0 04 lda #$00 ; A9 00 sta $00 ; 85 00 L17B7: lda $00 ; A5 00 beq L1810 ; F0 55 lda NGFLAG ; A5 01 beq L1810 ; F0 51 dec L0663 ; CE 63 06 lda L0663 ; AD 63 06 bne L1810 ; D0 49 dec L00CB ; C6 CB bne L17E5 ; D0 1A lda #$02 ; A9 02 sta L00CB ; 85 CB lda PTRIG0 ; AD 7C 02 bne L17D7 ; D0 03 dec L0664 ; CE 64 06 L17D7: lda PTRIG1 ; AD 7D 02 bne L17DF ; D0 03 inc L0664 ; EE 64 06 L17DF: lda L0664 ; AD 64 06 sta HPOSP0 ; 8D 00 D0 L17E5: lda $00 ; A5 00 sta L0663 ; 8D 63 06 dec L0662 ; CE 62 06 ldx L0662 ; AE 62 06 stx VSCROL ; 8E 05 D4 bne L1810 ; D0 1B ldy #$00 ; A0 00 sec ; 38 lda (TRAMSZ),Y ; B1 06 sbc #$14 ; E9 14 sta (TRAMSZ),Y ; 91 06 ldy #$01 ; A0 01 lda (TRAMSZ),Y ; B1 06 sbc #$00 ; E9 00 sta (TRAMSZ),Y ; 91 06 lda #$07 ; A9 07 sta L0662 ; 8D 62 06 sta VSCROL ; 8D 05 D4 dec NGFLAG ; C6 01 L1810: jmp XITVBV ; 4C 62 E4 .byte $00,$00,$00,$00 pla ; 68 ldx #$E4 ; A2 E4 ldy #$62 ; A0 62 lda #$07 ; A9 07 jsr SETVBV ; 20 5C E4 rts ; 60 L1822: lda RANDOM ; AD 0A D2 and #$03 ; 29 03 cmp #$03 ; C9 03 bcs L1822 ; B0 F7 rts ; 60 tax ; AA lda #$48 ; A9 48 cpx #$01 ; E0 01 beq L1839 ; F0 06 lda #$49 ; A9 49 bcc L1839 ; 90 02 lda #$00 ; A9 00 L1839: sta (L00CB),Y ; 91 CB rts ; 60 L183C: lda L00CE ; A5 CE sta L00CD ; 85 CD lda RANDOM ; AD 0A D2 and #$07 ; 29 07 clc ; 18 adc #$06 ; 69 06 tay ; A8 lda #$86 ; A9 86 sta (L00CB),Y ; 91 CB lda RANDOM ; AD 0A D2 bmi L1860 ; 30 0E lda #$17 ; A9 17 sta L00CF ; 85 CF lda #$12 ; A9 12 sta L00D0 ; 85 D0 lda #$16 ; A9 16 sta L00D1 ; 85 D1 bne L186C ; D0 0C L1860: lda #$11 ; A9 11 sta L00CF ; 85 CF lda #$16 ; A9 16 sta L00D0 ; 85 D0 lda #$12 ; A9 12 sta L00D1 ; 85 D1 L186C: sec ; 38 tya ; 98 sbc L00D1 ; E5 D1 tay ; A8 ldx #$03 ; A2 03 L1873: tya ; 98 clc ; 18 adc L00CF ; 65 CF tay ; A8 lda #$CC ; A9 CC sta (L00CB),Y ; 91 CB tya ; 98 clc ; 18 adc L00D0 ; 65 D0 tay ; A8 lda #$CC ; A9 CC sta (L00CB),Y ; 91 CB dex ; CA bne L1873 ; D0 EB rts ; 60 pla ; 68 pla ; 68 sta L00CC ; 85 CC pla ; 68 sta L00CB ; 85 CB lda #$00 ; A9 00 sta L00CD ; 85 CD lda #$18 ; A9 18 sta L00CE ; 85 CE L1898: jsr L0671 ; 20 71 06 tay ; A8 L189C: jsr L0671 ; 20 71 06 jsr L067B ; 20 7B 06 dey ; 88 bpl L189C ; 10 F7 ldy #$11 ; A0 11 jsr L0671 ; 20 71 06 cmp #$01 ; C9 01 beq L18B2 ; F0 04 iny ; C8 bcc L18B2 ; 90 01 iny ; C8 L18B2: jsr L0671 ; 20 71 06 jsr L067B ; 20 7B 06 iny ; C8 cpy #$14 ; C0 14 bne L18B2 ; D0 F5 lda RANDOM ; AD 0A D2 cmp #$0D ; C9 0D bcs L18D6 ; B0 12 clc ; 18 lda L00CD ; A5 CD adc #$0A ; 69 0A cmp L00CE ; C5 CE bcs L18D6 ; B0 09 jsr L068B ; 20 8B 06 beq L1906 ; F0 34 bne L18D6 ; D0 02 L18D4: bne L1898 ; D0 C2 L18D6: lda RANDOM ; AD 0A D2 cmp #$19 ; C9 19 bcs L18E1 ; B0 04 lda #$07 ; A9 07 bne L18F5 ; D0 14 L18E1: lda RANDOM ; AD 0A D2 cmp #$19 ; C9 19 bcs L18EC ; B0 04 lda #$0A ; A9 0A bne L18F5 ; D0 09 L18EC: lda RANDOM ; AD 0A D2 cmp #$19 ; C9 19 bcs L1906 ; B0 13 lda #$8B ; A9 8B L18F5: tax ; AA L18F6: lda RANDOM ; AD 0A D2 and #$0F ; 29 0F cmp #$0C ; C9 0C bcs L18F6 ; B0 F7 clc ; 18 adc #$03 ; 69 03 tay ; A8 txa ; 8A sta (L00CB),Y ; 91 CB L1906: inc L00CE ; E6 CE lda L00CE ; A5 CE cmp #$AF ; C9 AF bne L190F ; D0 01 rts ; 60 L190F: clc ; 18 lda #$14 ; A9 14 adc L00CB ; 65 CB sta L00CB ; 85 CB lda L00CC ; A5 CC adc #$00 ; 69 00 sta L00CC ; 85 CC bne L18D4 ; D0 B6 .byte $00 Quote Link to comment Share on other sites More sharing options...
drac030 Posted February 11, 2009 Share Posted February 11, 2009 LA881 = $A881 LA8E3 = $A8E3 LA8FD = $A8FD LA94C = $A94C LAC28 = $AC28 The program directly calls these locations inside the Atari BASIC interpreter. Rev. B and C have them, naturally, somewhere else, ans these routines are not to be called by user programs... Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted February 11, 2009 Share Posted February 11, 2009 It looks like there's only a few addresses you need to be concerned about...$A881, $A8FD, $A8E3, $A94C, and $AC28. These are calls to the cartridge itself, the hardware equates should all be correct since it's only the Basic that differs. Did you take a peek under the hood of the 2 Basics? Look at $A881 in rev.A and then try to find matching code in rev.C, etc? Quote Link to comment Share on other sites More sharing options...
Bryan Posted February 11, 2009 Share Posted February 11, 2009 If it's just borrowing some routines, maybe they could be duplicated within the asm section. If it's trying to affect the operation of BASIC, then it could be modified to use different locations based on the BASIC version. Quote Link to comment Share on other sites More sharing options...
kenfused Posted February 12, 2009 Share Posted February 12, 2009 It looks like there's only a few addresses you need to be concerned about...$A881, $A8FD, $A8E3, $A94C, and $AC28. These are calls to the cartridge itself, the hardware equates should all be correct since it's only the Basic that differs. Did you take a peek under the hood of the 2 Basics? Look at $A881 in rev.A and then try to find matching code in rev.C, etc? http://users.telenet.be/kim1-6502/6502/p3.html#141 A881 Expand (move stuff up in memory) A8FD Contract (move stuff down in memory) A8EC, A94C located within the above two AC28-Get Value's Value Table Entry Address Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted February 12, 2009 Share Posted February 12, 2009 A881 Expand (move stuff up in memory)A8FD Contract (move stuff down in memory) A8EC, A94C located within the above two AC28-Get Value's Value Table Entry Address Thanks for that. A quick dump under Atari800win shows... (RevA -> RevC) $A881 -> $A87C $A8FD -> $A8FA $A8EC -> $A8E8 $A94C -> $A949 $AC28 -> $AC1E Since the expand and contract routines have been altered slightly in Rev.C, I can't guarantee that the code needed will work exactly as predicted. But those are the matching entrypoints in the cart. Quote Link to comment Share on other sites More sharing options...
NuY Posted February 12, 2009 Author Share Posted February 12, 2009 A881 Expand (move stuff up in memory)A8FD Contract (move stuff down in memory) A8EC, A94C located within the above two AC28-Get Value's Value Table Entry Address Thanks for that. A quick dump under Atari800win shows... (RevA -> RevC) $A881 -> $A87C $A8FD -> $A8FA $A8EC -> $A8E8 $A94C -> $A949 $AC28 -> $AC1E Since the expand and contract routines have been altered slightly in Rev.C, I can't guarantee that the code needed will work exactly as predicted. But those are the matching entrypoints in the cart. I actually got round to fixing this last night with your initial post about finding equivalent entry points in the rev C carts, so I disassembled the A and C carts, (the places it jumps into seem incredibly abitrary at points...), found the instances where the code looked the same (or similar) and altered them in the original MC. Then used a Windows hex editor to alter the code that I dumped from Atari, threw it all back into the original Atari Basic prog, and presto, it worked Luckily the code in rev C was modified only slightly from A in the bits that this proggy accesses, a couple of NOPs to pad out redundant instructions and stuff. That polishes off the games in this book now! Thanks all for your help, especially Nukey Shay. I know I asked if someone would be able to modify it themselves, but obviously I just needed a programmer's perspective and hints to get in the right direction Thanks guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.