1
0
mirror of https://github.com/specht/champ.git synced 2024-10-03 07:55:31 +00:00
This commit is contained in:
Michael Specht 2018-02-05 23:15:26 +01:00
parent 10ddcf58ed
commit d7161b71c6
4 changed files with 4810 additions and 5 deletions

67
champ.c
View File

@ -4,6 +4,7 @@
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "labels.h"
#define SCALE 4
#define SCREEN_WIDTH 280
@ -25,8 +26,15 @@ unsigned int white, black;
Atom wmDelete;
XEvent evt;
KeyCode keyQ;
uint8_t show_screen = 0;
uint8_t show_log = 1;
uint8_t show_call_stack = 0;
uint8_t trace_stack[0x100];
uint8_t trace_stack_pointer = 0xff;
uint16_t trace_stack_function[0x100];
uint64_t cycles_per_function[0x10000];
int init_display()
{
@ -787,6 +795,22 @@ void handle_next_opcode()
break;
case JSR:
// push IP - 1 because target address has already been read
// if (label_for_address[target_address] >= 0)
// {
// for (int i = trace_stack_pointer; i < 0xff; i++)
// printf(" ");
// printf("JSR: %s\n", LABELS[label_for_address[target_address]]);
// }
// else
// {
// for (int i = trace_stack_pointer; i < 0xff; i++)
// printf(" ");
// printf("JSR: %04x\n", target_address);
// }
trace_stack_function[trace_stack_pointer] = target_address;
trace_stack[trace_stack_pointer] = cpu.sp;
trace_stack_pointer--;
push(((cpu.ip - 1) >> 8) & 0xff);
push((cpu.ip - 1) & 0xff);
cpu.ip = target_address;
@ -883,6 +907,16 @@ void handle_next_opcode()
cpu.ip = t16;
break;
case RTS:
if (trace_stack[trace_stack_pointer + 1] == cpu.sp + 2)
{
trace_stack_pointer++;
// for (int i = trace_stack_pointer; i < 0xff; i++)
// printf(" ");
// printf("RTS: .... %02x\n", cpu.sp + 2);
}
// else
// printf("ommitting RTS from stack trace...\n");
t16 = pop();
t16 |= ((uint16_t)pop()) << 8;
cpu.ip = t16 + 1;
@ -945,10 +979,20 @@ void handle_next_opcode()
exit(1);
}
cpu.total_cycles += cycles;
if (trace_stack_pointer < 0xff)
cycles_per_function[trace_stack_function[trace_stack_pointer + 1]] += cycles;
if (show_log)
{
printf("A: %02x, X: %02x, Y: %02x, FLAGS: %02x, PC: %04x, SP: %02x | %10ld",
cpu.a, cpu.x, cpu.y, cpu.flags, cpu.ip, cpu.sp, cpu.total_cycles);
char flags_str[6];
flags_str[0] = test_flag(CARRY) ? 'C' : 'c';
flags_str[1] = test_flag(ZERO) ? 'Z' : 'z';
flags_str[2] = test_flag(DECIMAL_MODE) ? 'D' : 'd';
flags_str[3] = test_flag(OVERFLOW) ? 'V' : 'v';
flags_str[4] = test_flag(NEGATIVE) ? 'N' : 'n';
flags_str[5] = 0;
printf("A: %02x, X: %02x, Y: %02x, PC: %04x, SP: %02x, FLAGS: %02x %s | %10ld |",
cpu.a, cpu.x, cpu.y, cpu.ip, cpu.sp, cpu.flags, flags_str, cpu.total_cycles);
printf("\n");
}
}
@ -997,7 +1041,9 @@ int main(int argc, char** argv)
if (strcmp(argv[i], "--hide-log") == 0)
show_log = 0;
}
memset(ram, 0, 0x10000);
memset(ram, 0, sizeof(ram));
memset(cycles_per_function, 0, sizeof(cycles_per_function));
load(argv[argc - 1], 0);
if (show_screen)
@ -1011,8 +1057,8 @@ int main(int argc, char** argv)
uint32_t next_display_refresh = 0;
uint8_t old_screen_number = 0;
while (1) {
if (cpu.ip >= 0xf5b2)
printf("*** ");
// if (cpu.ip >= 0xf5b2)
// printf("*** ");
handle_next_opcode();
// if (cycles)
// {
@ -1055,5 +1101,16 @@ int main(int argc, char** argv)
}
}
printf("Total cycles: %d\n", cpu.total_cycles);
for (uint32_t i = 0; i < 0x10000; i++)
{
if (cycles_per_function[i] > 0)
{
printf("%12d %5.2f%% %04x", cycles_per_function[i],
cycles_per_function[i] * 100.0 / cpu.total_cycles, i);
if (label_for_address[i] >= 0)
printf(" %s", LABELS[label_for_address[i]]);
printf("\n");
}
}
return 0;
}

4207
labels.h Normal file

File diff suppressed because it is too large Load Diff

63
parse.rb Executable file
View File

@ -0,0 +1,63 @@
#!/usr/bin/env ruby
label_for_address = {}
symbols = []
File::open('plot3d20_Output.txt') do |f|
f.each_line do |line|
parts = line.split('|')
next unless parts.size == 8
address = parts[6].split(' ').first.split('/')[1]
symbol = parts[7]
symbol = symbol[1, symbol.size - 1]
next if symbol[0] == '*'
next if symbol[0] == ';'
next if symbol[0] == ' '
symbol = symbol.strip.split(' ').first
next if address.nil?
label_for_address[address.to_i(16)] = symbol
symbols << symbol
end
end
symbols.uniq!
symbols.sort! { |a, b| a.downcase <=> b.downcase }
File::open('labels.h', 'w') do |f|
f.puts "const char* LABELS[] = {";
line_length = 0
f.print ' '
symbols.each.with_index do |symbol, _|
part = "\"#{symbol}\""
if _ < symbols.size - 1
part += ', '
end
f.print part
line_length += part.size
if line_length > 60
f.puts
f.print ' '
line_length = 0
end
end
f.puts "};"
f.puts "const int16_t label_for_address[] = {"
f.print ' '
(0..0xffff).each do |address|
value = -1
if label_for_address.include?(address)
value = symbols.index(label_for_address[address]);
end
f.print "#{value}, "
if (address + 1) % 16 == 0
f.puts
f.print ' '
end
end
f.puts "};";
end
# label_for_address.keys.sort.each do |address|
# puts sprintf("%04x %s", address, label_for_address[address])
# end

478
symbols.txt Normal file
View File

@ -0,0 +1,478 @@
6000 ENTRY
6003 SETONCE
601a TABLESET
601d LOOP
6020 EVJOY
602e noROTmode
6038 RDPDLS
603d PREAD0
604c DECSPDY
606e INCSPDY
608d PREAD1
609c DECSPDX
60be INCSPDX
60dd READKBD
60e5 KEYPOINT
60e9 INCSPDZ
6108 NOINCZ
610b KEYCOMMA
610f DECSPDZ
612e NODECZ
6131 KEY1
6153 KEY2
6175 KEY3
6197 KEY4
61b9 KEY5
61db KEYO
61e5 KEYPLUS
620f keypend
6212 KEYMINUS
623c keymend
623f KEYQ
6249 KEYE
6257 WENDSON
625d KEYR
626b ROTMODEON
6271 KEYS
627f SSTEPON
6285 KEYW
6293 HQWIREON
6296 ENDKEY10
6299 KEYH
62a7 HHOLDON
62ac KEYN
62ba NNORMAL
62bf KEYL
62cd HHIDDEN
62d2 KEYF
62e0 RRFILL
62ea KEYP
62fc PPROJECT
6305 KEYC
6311 noKEYC
6314 clpCTRL
631e KEYJ
6327 KEYK
6330 KEYI
6339 KEYM
6340 clpEND
6345 ENDKEY
634e ENDKEY1
6351 NOKEY
6365 HHLD2
636a PB1LOOP
636c PB0CHK
637a chkHOLD
6387 DOSTEP
638a drwLOOP
63cc jp1
63ce udrws2
6404 DRWLNS
640f DRWSCR10
6411 DP1
641e swOBJ
644d OB_Init
6452 OB_Loop
6457 Show_2
64c4 Show_1
652f Modi_1
661b noHQWIRE
662c noCLP1
6630 ChkSize
6633 P2_24
6640 Chk1
6648 Chk2
664a P2_25
6655 Chk3
665d Chk4
6668 NoBBox
6672 F2_4
6678 F2_5
667e F2_6
6684 F2_7
6689 save_2
668c F2_8
6692 F2_9
6698 F2_10
669e F2_11
66a1 clr_flg
66a7 RSTPNT
66aa P1_1
66ad P2_1
66c1 OB_End
66d0 DISP2
66d9 GOLOOP
66dc END
66ed drwBBOX
6742 mvCLPleft
6772 CLPlRTS
6773 mvCLPright
67a3 CLPrRTS
67a4 mvCLPup
67d4 CLPuRTS
67d5 mvCLPdown
6805 CLPdRTS
6806 StoreOBData
6835 StoreOB1
685f GetOBData
688e GetOB1
68b8 DOCLIP
68bf setCLIP
68cf clpERASE0
6908 clpERASE
692c ToggleObject
6943 Tog2
6953 PRTVARS
6962 prtCont
699d CHKNEG
69ad equal
69b0 greater
69b5 smaller
69be cont
69c2 ctemp1
69c3 SETUP
6aaa SETUPCLP
6aca SETUPWHITE
6ad3 WhLp1
6adf SetWhite2
6ae1 WhLp2
6aec SetupRTS
6aed setANDMSK
6b0a clrANDMSK
6b27 INITPNTS
6b50 FACELOOP
6b58 GETPNT
6b5d F1_1
6b62 F2_1
6b68 F1_2
6b6d F2_2
6b73 F1_3
6b78 F2_3
6b80 F1_4
6b8c doROTMAT
6bbd NOPROJ
6bfb NOHIDDEN
6c06 NORFILL
6c07 DRWFAC
6c0c NXTLIN
6c14 DOLNDRW
6c16 DRWLIN
6c1e CHKLIN
6c26 DODRWLIN
6c29 NORFILL3
6c2a P1_4
6c31 P1_5
6c39 P2_2
6c41 DOPNT1
6c45 P2_4
6c4b P2_5
6c51 P2_6
6c7e NOPROJ2
6c8b P2_7
6c8f P2_8
6c99 P2_8a
6c9c CALCYD3
6ca9 P2_9
6cac DOPNT2
6cb1 P2_10
6cb9 DOPNT2_1
6cbd P2_12
6cc3 P2_13
6cc9 P2_14
6cf6 NOPROJ3
6d03 P2_15
6d07 P2_16
6d11 P2_16a
6d14 CALCYD2
6d21 P2_17
6d24 PNTSDONE
6d29 P2_18
6d2f P2_19
6d35 P2_20
6d3a DRWPNT2
6d3f P2_21
6d45 P2_22
6d4b P2_23
6d5a CHKCLP
6d62 NOCLIP
6d65 DRWLINEN
6d6a DRWFACEN
6d88 DoFill
6d8b WRTCONT
6d97 DRWCLPFR
6da5 DRWEND
6da6 doCLPFRM
6df1 erCLPFRM
6e3c FixRasterTable
6e47 ChkRastBot
6e52 StartFix
6e55 FixLoop
6e63 ChkRight
6e73 FixCont
6e7b FixEnd
6e7c CLIPLNS
6e94 CLIPLNS1
6e9a XDRAWLF
6ea4 CLPLL1
6ece NODIVI
6edd XTOLEFT
6f0e NODIVI2
6f1a CLPRIGHT
6f31 CLIPLNS2
6f37 XDRAWLF2
6f41 CLPLL2
6f69 NODIVI3
6f78 XTOLEFT2
6fa7 NODIVI4
6fb3 CLIPTOP
6fc6 CLIPLNS3
6fcc YDRAWBO
6fd6 CLIPTOP2
700d YTOBOT
7048 CLIPBOT
705b CLIPLNS4
7061 YDRAWBOT
706b CLPLL4
70a2 YTOBOT2
70dd CLIPEND4
70de ROTMAT
71cb LOAD1
71e1 poke1
71eb LOAD01
71f4 OBJNAME
720e PRINT
7216 P0
7221 PFIN
722f PEXIT
7230 UDRWLNS
7260 ldascr
726a UDRWSCR1
7294 UDRWLP1
729c UDRWBRA1
729f BRA1
741f RvtRTS1
7428 UDRW1RTS
742d UDRWSCR2
7457 UDRWLP2
745f UDRWBRA2
7462 BRA2
75e2 RvtRTS2
75eb UDRW2RTS
75f0 XCOMP
75f1 YJUMP2
75f3 YJUMP1
75f5 LINEDRAW
7603 LX0RIGHT
7612 NOINCHI
7624 CHKVERT
762f phorizontal
7630 LX0LEFT
7643 LNCOMMON
764f LPOSY
7655 GOTDY
7672 HORIDOM
768b LOTABLE
7691 GOTTAB
76a6 chkwdflag
76ad NOTWIDE
76b0 HRTS
76b1 HNOROLL
76b3 HDECC
76b7 NOPLT1
76c1 chkbot1
76cb chkrast1
76d5 chkrast1a
76df ldadiff2
76eb NOH8
76f8 LHMODY
7707 bnehdecc
770b VERTDOM
7713 ENDY0
772b LOTABLL
7731 GOTTAB2
773b VNOROLL
773d VERTLOOP
7751 chkbot2
775b chkrast2
7765 chkrast2a
776f LVCHK
7773 LVMODY
778c IS8
7793 VRTS
7794 WIDEDOM
77a5 NOPLT3
77b1 NOT7
77bb chkbot3
77c5 chkrast3
77cf chkrast3a
77d9 ldadiff
77ee LWMODY
77fb bnewdecc
77ff WNOROLL
7801 WDECC
780e VERTLINE
781a USEY0
7830 LOTABL2
7836 GOTIT
783b PVERLOOP
7851 chkbot4
785b chkrast4
7865 chkrast4a
786f NOPLT4
7872 LPVYTEST
7877 FASTLINE
7885 fLX0RIGHT
7893 fNOINCHI
78a5 fCHKVERT
78b0 fphorizontal
78d6 fphori_rts
78d7 fLX0LEFT
78ea fLNCOMMON
78f6 fLPOSY
78fc fGOTDY
7919 fHORIDOM
792e fLOTABLE
7934 fGOTTAB
7947 fNOTWIDE
794a fHRTS
794b fHNOROLL
794d fHDECC
7951 fHORZLOOP
7953 oraA1
7961 fNOH8
796e fLHMODY
797d fVERTDOM
7985 fENDY0
799b fLOTABLL
79a1 fGOTTAB2
79ab fVNOROLL
79ad fVERTLOOP
79bb oraA2
79bf fLVCHK
79c3 fLVMODY
79da fIS8
79e1 fVRTS
79e2 fWIDEDOM
79f3 fWIDELOOP
79f5 oraA3
7a03 fNOT7
7a1a fLWMODY
7a29 fWNOROLL
7a2b fWDECC
7a38 fVERTLINE
7a44 fUSEY0
7a58 fLOTABL2
7a5e fGOTIT
7a66 fPVERLOOP
7a74 fLPVAND
7a79 fLPVYTEST
7a7e DIVI
7a96 DORCHK
7aa3 DIVIGO
7aab DLOOP
7ab4 SUBTR
7ab8 DCONT
7ad7 DIVEND
7ad8 UMULT
7ada UMTCHK
7aee UMDONE
7af0 MULT
7af2 MTCHK
7b10 CHKT2
7b17 MDONE
7b1b FMULT
7b1f FMTCHK
7b35 FCHKT2
7b3c FMDONE
7b3e SetColor
7b54 ozunid_1
7b57 __xormsk
7b5c _done
7b5d fillraster
7b6b _goodmask
7b72 rastloop
7b7c _pg_or1
7b93 _firstre
7b9a _noflag
7ba8 _lotabl
7bb2 _gotlft
7bc6 _lotabr
7bd0 _repeat
7bf0 _not1byte
7c0e _rgtnospcl
7c2a _lftnospcl
7c2c _liny
7c35 __rastun
7c38 rastlinedone
7c52 WH2_1
7c64 WH2_2
7c66 noWENDS
7c68 INC_Y
7c6c rast_done
7c6d ]offset
7d00 rast_unroll
7dcb ]offset
7df4 RastReset
7dfa RSTLP1
7e08 RSTLP2
7e1a WLCMTXT
7e2a STDTEXT
7e5b TXTOUT
7e69 TXTLOOP
7e8b GETBYTE
7e90 G1
7ead ToPage2
7ebf TOutDone
7ecc TXTDONE
7ecd CHARCOUNT
7ece YLINENUM
7ecf TXTOB1
7edf TXTDAT
7f02 TXT2
7f06 TXT3
7f0a TXT4
7f2e TXT5
7f3d TXTO1
7f49 TXTO2
7f50 TXTO3
7f5c TXTO4
7f68 TXTO5
7f74 TXTDAT5
7f88 TXTDAT4
7f9f TXTDAT6
7fb4 TXTDAT7
7fca LCNT
7fcb XREGDUMP
7fcc YREGDUMP
7fcd SHPDUMP
7fce SHXPOS
7fcf DRAWBOX
800f DLTTXT
8017 DLTSTRT
801c DLTLOOP
8056 DLTEND
8057 YDELROW
8058 HEX2BCD
8061 CNVBIT
80ba setplus
80c1 setzero
80c6 BCDOUT
80d7 BIN
80d8 BCD
80da BSIGN
80db DIGITS
80dd DIG1
80de DIG2
80df DIG3
80e0 DIG4
80e1 ENDDIG
80e2 PRTLEG
8103 legCont
813a DISTLEG
8145 XSPEED
8150 YSPEED
815b ZSPEED
8166 PRTACT
817f actCont
81a0 ACTTEXT
81af ACTDEL