Hi guys,

Just wanted to share my latest lua project for fiddling with Apple disk images.

You can load a disk image into a global "mydisk" variable with:

loaddisk("stellar7.dsk")

then you can do

Code
catalog()
[MAME]> catalog()
(11,0f) 00  *B 003 LETTER                         TS List=(12,0f)
(11,0f) 01  *B 01a ROCK1                          TS List=(12,0c)
(11,0f) 02  *B 04f ROCK2                          TS List=(13,02)
(11,0f) 03  *B 007 ROCK3                          TS List=(18,03)
(11,0f) 04   B 022 TITLE                          TS List=(04,0f)
(11,0f) 05  *B 022 PANEL                          TS List=(1b,0a)
(11,0f) 06  *B 022 BRIEF                          TS List=(1d,08)
(11,0e) 00  *B 008 BRIEF.ST                       TS List=(1f,06)
(11,0e) 01  *B 019 PLAYGAME                       TS List=(20,0e)
(11,0e) 02  *B 00f BRIEFING                       TS List=(21,05)
(11,0e) 03  *B 00e LEV1                           TS List=(22,07)
(11,0e) 04  *B 00e LEV2                           TS List=(10,09)
(11,0e) 05  *B 00e LEV3                           TS List=(0f,0b)
(11,0e) 06  *B 00e LEV4                           TS List=(08,0f)
(11,0d) 00  *B 00e LEV5                           TS List=(0d,0f)
(11,0d) 01  *B 00e LEV6                           TS List=(07,0f)
(11,0d) 02  *B 00e LEV7                           TS List=(06,0f)
(11,0d) 03  *B 002 OBJ1                           TS List=(0b,05)
(11,0d) 04  *B 002 OBJ2                           TS List=(0b,03)
(11,0d) 05  *B 002 OBJ3                           TS List=(0b,01)
(11,0d) 06  *B 002 OBJ4                           TS List=(0a,0f)
(11,0c) 00  *B 002 OBJ5                           TS List=(0a,0d)
(11,0c) 01  *B 002 OBJ6                           TS List=(0a,0b)
(11,0c) 02  *B 002 OBJ7                           TS List=(0a,09)
(11,0c) 03  *B 003 DYN1                           TS List=(0a,07)
(11,0c) 04  *B 003 DYN2                           TS List=(0a,04)
(11,0c) 05  *B 003 DYN3                           TS List=(0a,01)
(11,0c) 06  *B 003 DYN4                           TS List=(09,0e)
(11,0b) 00  *B 003 DYN5                           TS List=(09,0b)
(11,0b) 01  *B 003 DYN6                           TS List=(09,08)
(11,0b) 02  *B 003 DYN7                           TS List=(09,05)
(11,0b) 03   B 002 HIGH                           TS List=(09,02)
(11,0b) 04   A 002 HELLO                          TS List=(19,0c)
(11,0b) 05   A 003 LEVELS VERTAUSCHEN             TS List=(1a,0f)
T=228 out of range
and if you want to load a file:
Code
[MAME]> a=getfileraw("LEVEL")
(11,0f) 00  *B 003 LETTER                         TS List=(12,0f)
...
(11,0b) 04   A 002 HELLO                          TS List=(19,0c)
(11,0b) 05   A 003 LEVELS VERTAUSCHEN             TS List=(1a,0f)
matched "LEVEL" with "LEVELS VERTAUSCHEN            "
You can do basic dumps
Code
[MAME]> basdump(a)
5   PRINT "LEVELS VERTAUSCHEN": PRINT 
10   PRINT 
15   INPUT "LEVEL1, LEVEL2 ZU TAUSCHEN ?";L1,L2
17   IF L1 = 0 OR L2 = 0 THEN 30
18  A$ = "UNLOCK":I = L1: GOSUB 100:I = L2: GOSUB 100
20  I = L1:A$ = "RENAME":J = 99: GOSUB 110:I = L2:J = L1: GOSUB 110:I = 99:J = L2: GOSUB 110
30  A$ = "LOCK":I = L1: GOSUB 100:I = L2: GOSUB 100
40   PRINT "FERTIG.": PRINT : RUN 
99   END 
100   PRINT A$"LEV"I: PRINT A$"OBJ"I: PRINT A$"DYN"I: RETURN 
110   PRINT A$"LEV"I",LEV"J: PRINT A$"OBJ"I",OBJ"J: PRINT A$"DYN"I",DYN"J: RETURN 
or hexdumps

Code
[MAME]> hexdump(a)
00   5c 01 1d 08 05 00 ba 22  |  4c 45 56 45 4c 53 20 56  |  \.....:"LEVELS V
10   45 52 54 41 55 53 43 48  |  45 4e 22 3a ba 00 23 08  |  ERTAUSCHEN"::.#.
20   0a 00 ba 00 4d 08 0f 00  |  84 22 4c 45 56 45 4c 31  |  ..:.M...."LEVEL1
30   2c 20 4c 45 56 45 4c 32  |  20 5a 55 20 54 41 55 53  |  , LEVEL2 ZU TAUS
40   43 48 45 4e 20 3f 22 3b  |  4c 31 2c 4c 32 00 5f 08  |  CHEN ?";L1,L2._.
50   11 00 ad 4c 31 d0 30 ce  |  4c 32 d0 30 c4 33 30 00  |  ..-L1P0NL2P0D30.
60   84 08 12 00 41 24 d0 22  |  04 55 4e 4c 4f 43 4b 22  |  ....A$P".UNLOCK"
70   3a 49 d0 4c 31 3a b0 31  |  30 30 3a 49 d0 4c 32 3a  |  :IPL1:0100:IPL2:
80   b0 31 30 30 00 c2 08 14  |  00 49 d0 4c 31 3a 41 24  |  0100.B...IPL1:A$
90   d0 22 04 52 45 4e 41 4d  |  45 22 3a 4a d0 39 39 3a  |  P".RENAME":JP99:
a0   b0 31 31 30 3a 49 d0 4c  |  32 3a 4a d0 4c 31 3a b0  |  0110:IPL2:JPL1:0
b0   31 31 30 3a 49 d0 39 39  |  3a 4a d0 4c 32 3a b0 31  |  110:IP99:JPL2:01
c0   31 30 00 e5 08 1e 00 41  |  24 d0 22 04 4c 4f 43 4b  |  10.e...A$P".LOCK
d0   22 3a 49 d0 4c 31 3a b0  |  31 30 30 3a 49 d0 4c 32  |  ":IPL1:0100:IPL2
e0   3a b0 31 30 30 00 f8 08  |  28 00 ba 22 46 45 52 54  |  :0100.x.(.:"FERT
f0   49 47 2e 22 3a ba 3a ac  |  00 fe 08 63 00 80 00 22  |  IG.":::,.~.c.�."
100   09 64 00 ba 41 24 22 4c  |  45 56 22 49 3a ba 41 24  |  .d.:A$"LEV"I::A$
110   22 4f 42 4a 22 49 3a ba  |  41 24 22 44 59 4e 22 49  |  "OBJ"I::A$"DYN"I
120   3a b1 00 5b 09 6e 00 ba  |  41 24 22 4c 45 56 22 49  |  :1.[.n.:A$"LEV"I
130   22 2c 4c 45 56 22 4a 3a  |  ba 41 24 22 4f 42 4a 22  |  ",LEV"J::A$"OBJ"
140   49 22 2c 4f 42 4a 22 4a  |  3a ba 41 24 22 44 59 4e  |  I",OBJ"J::A$"DYN
150   22 49 22 2c 44 59 4e 22  |  4a 3a b1 00 00 00 4c 00  |  "I",DYN"J:1...L.
160   00 00 00 00 00 00 00 00  |  00 00 00 00 00 00 00 00  |  ................
...
1f0   00 00 00 00 00 00 00 00  |  00 00 00 00 00 00 00 00  |  ................

DONE

You can get the track sector list

Code
[MAME]> printt(gettslist(0x12,0xf))
{{0x12 18, 0xe 14}, 
{0x12 18, 0xd 13}}
or you can do textdumps:

Code
[MAME]> a=getfile("LET")
(11,0f) 00  *B 003 LETTER                         TS List=(12,0f)
matched "LET" with "LETTER                        "
BLOAD ADDR=(01,09)  0901   DATA LENGTH=(26,01) DATA LENGTH=0126
LEN ORIG:	200
LEN AFTER:	126
[MAME]> textdump(a)
00                STELLAR 7.
38   .
39   YOU SHOULDN'T BE READING THIS, BUT IF.
You can load a picture file:
Code
bload("BRIEF",0x2000)
hgr()

and a neat-o function to print tables:
Code
 printt({"why","lisa",{"you're tearing me apart","oh hi","mark"}})
{"why", 
"lisa", 
{"you're tearing me apart", "oh hi", "mark"}}

printt(manager:machine().devices)
{":a2video" = sol.device_t*: 0x5585abc0fa28, 
":a2bus" = sol.device_t*: 0x5585abc09028, 
":sl6:diskiing:0:525" = sol.device_t*: 0x5585abc08de8, 
":sl4:mockingboard:mockbd_via2" = sol.device_t*: 0x5585abc09268, 
":r40bank" = sol.device_t*: 0x5585abc0f7a8, 
...
":r20bank" = sol.device_t*: 0x5585abc0fb68}

You can bload files:

Code
[MAME]> loaddisk("serpentine_bolocheat_pestpatrol.dsk")
[MAME]> bload("PEST")
(11,0f) 00   A 003 HELLO                          TS List=(05,0f)
(11,0f) 01  *T 002 SERPENTINE*                    TS List=(15,0a)
(11,0f) 02  *B 00a SERPENTINE 00-08               TS List=(15,08)
(11,0f) 03  *B 03a SERPENTINE 08-40               TS List=(16,0e)
(11,0f) 04  *B 052 SERPENTINE 40-90               TS List=(19,04)
(11,0f) 05  *B 02a SERPENTINE 90-B8               TS List=(1e,02)
(11,0f) 06  *B 00a SERPENTINE B8-C0               TS List=(21,08)
(11,0e) 00  *B 022 BOLOSCREEN                     TS List=(05,0c)
(11,0e) 01  *B 012 BOLO                           TS List=(03,0a)
(11,0e) 02  *B 060 BOLO.BINARY                    TS List=(02,08)
(11,0e) 03   A 007 BOLO-CHEATER                   TS List=(10,0c)
(11,0e) 04  *B 08c PEST PATROL                    TS List=(07,0f)
matched "PEST" with "PEST PATROL                   "
BLOAD ADDR=(fd,0c)  0cfd   DATA LENGTH=(03,89) DATA LENGTH=8903
LEN ORIG:	8a00
LEN AFTER:	8903

and you can bload a file and execute it like a brun but you have to stop the cpu first with stop() for synchronization reasons:

Code
[MAME]> stop()
[MAME]> bload("PEST",nil,nil,true)
(11,0f) 00   A 003 HELLO                          TS List=(05,0f)
(11,0f) 01  *T 002 SERPENTINE*                    TS List=(15,0a)
(11,0f) 02  *B 00a SERPENTINE 00-08               TS List=(15,08)
(11,0f) 03  *B 03a SERPENTINE 08-40               TS List=(16,0e)
(11,0f) 04  *B 052 SERPENTINE 40-90               TS List=(19,04)
(11,0f) 05  *B 02a SERPENTINE 90-B8               TS List=(1e,02)
(11,0f) 06  *B 00a SERPENTINE B8-C0               TS List=(21,08)
(11,0e) 00  *B 022 BOLOSCREEN                     TS List=(05,0c)
(11,0e) 01  *B 012 BOLO                           TS List=(03,0a)
(11,0e) 02  *B 060 BOLO.BINARY                    TS List=(02,08)
(11,0e) 03   A 007 BOLO-CHEATER                   TS List=(10,0c)
(11,0e) 04  *B 08c PEST PATROL                    TS List=(07,0f)
matched "PEST" with "PEST PATROL                   "
BLOAD ADDR=(fd,0c)  0cfd   DATA LENGTH=(03,89) DATA LENGTH=8903
LEN ORIG:	8a00
LEN AFTER:	8903
pc=cfd
g

It's a little too large to include in a forum post so you can find it at:

https://github.com/goldnchild/goldenchilds_apple2_lua_stuff/blob/master/diskimage_file.lua