DM42 Decoder

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: https://technical.swissmicros.com/decoders/dm42/

You can then copy/paste the listing and post it in "code" tags.
Post Reply
hsilop
Posts: 70
Joined: Thu Mar 14, 2019 1:35 am
Location: Canberra, Australia

DM42 Decoder

Post by hsilop »

Here is a DM42 Decoder. It can decode the modified stress program attached. I hope someone finds a use for it.

The uploaded does not allow PHP files, so the code is below.

Code: Select all

<?php

/*
	DM42 decoder

	Usage: php DM42decoder.php <filename>.raw. Human readable output
	is written to <filename>.txt.

	Steve Green 20 March 2019 - 7 Jun 2023
*/

	function dumpn($in,$out,$n,$nl){
		fprintf($out,"\"");
		for ($i=1;$i<=$n;$i++) {
			$ch = fgetc($in);
			fprintf($out,"%s",$ch);
		}
		fprintf($out,"\"");
		if ( $nl )
			fprintf($out,"\n");
	}

	function fixlen($l) {
		return $l - 0xf1;
	}
	
	function reg($out,$r){
		$r = $r &0x7F;
		switch ($r) {
			case 0x74:fprintf($out,"L\n");break;
			case 0x73:fprintf($out,"X\n");break;
			case 0x72:fprintf($out,"Y\n");break;
			case 0x71:fprintf($out,"Z\n");break;
			case 0x70:fprintf($out,"T\n");break;
		}
	}
	
	function regstuff($out,$c) {
		if ( $c <= 0x63 )
			fprintf($out,"%02d\n",$c);
		else {
			if ( $c >= 0x80 && $c <= 0xE3)
				fprintf($out,"IND %02d\n",$c-0x80);
			else {
				if ( $c >= 0x70 && $c <= 0x74 )
					fprintf($out,"ST ",);
				else {
					fprintf($out,"IND ST ");
					$c = $c - 0x80;
				}
				reg($out,$c);
			}
		}
	}
	
	function gtoregstuff($out,$c) {
		if ( $c <= 0x63 )
			fprintf($out,"%02d\n",$c);
		else {
			fprintf($out,"ST ");
			reg($out,$c);
		}
	}
	
	function alpha_label($in,$out,$cmd) {
		fprintf($out,"%s ",$cmd);
		$len = ord(fgetc($in));
		dumpn($in,$out,fixlen($len)+1,true);
	}
	
	function alpha_thing($in,$out,$cmd,$len) {
		fprintf($out,"%s ",$cmd);
		dumpn($in,$out,fixlen($len),true);
	}
		
	function reg_thing($in,$out,$cmd){
		$c = ord(fgetc($in));
		fprintf($out,"%s ",$cmd);
		regstuff($out,$c);
	}
	
	// Main program

	$infile = $_SERVER["argv"][1];

	$info = pathinfo($infile);
	$outfile = str_replace(".raw",".txt",$info['basename']);
	
	Print "Input filename is " . $infile . " Output filename is " . $outfile . "\n";

	$in = fopen($infile,"r") or die("Unable to open input file " . $infile . "\n");
	$out = fopen($outfile,"w") or die("Unable to open output file " . $outfile . "\n");

	$ln=0;
	$eol = true;
	$fs = filesize($infile);
	fprintf($out,"00 {%d-Byte Prgm }\n",$fs-3);
	
	while (!feof($in)) {
		$ch = fgetc($in);	
		if ( $eol == true && $ch != 0x00 )
			fprintf($out,"%02d ",++$ln);	// line number
		$cmd = ord($ch);
		$eol = true;
		
	//	printf("Char %s hex maps to %x\n",$ch,$cmd);
		
		switch ($cmd) {
			case 0x02:	// short LBL
			case 0x03:
			case 0x04:
			case 0x05:
			case 0x06:
			case 0x07:
			case 0x08:
			case 0x09:
			case 0x0A:
			case 0x0B:
			case 0x0C:
			case 0x0D:
			case 0x0E:
			case 0x0F:fprintf($out,"LBL %02d\n",$cmd-1);break;
				
			case 0x1D:alpha_label($in,$out,"GTO");break;	
			case 0x1E:alpha_label($in,$out,"XEQ");break;				
			case 0x20:	// RCL local 
			case 0x21:
			case 0x22:
			case 0x23:
			case 0x24:
			case 0x25:
			case 0x26:
			case 0x27:
			case 0x28:
			case 0x29:
			case 0x2A:
			case 0x2B:
			case 0x2C:
			case 0x2D:
			case 0x2E:
			case 0x2F:fprintf($out,"RCL %02d\n",$cmd - 0x20);break;
			case 0x30:	// STO local 
			case 0x31:
			case 0x32:
			case 0x33:
			case 0x34:
			case 0x35:
			case 0x36:
			case 0x37:
			case 0x38:
			case 0x39:
			case 0x3A:
			case 0x3B:
			case 0x3C:
			case 0x3D:
			case 0x3E:
			case 0x3F:fprintf($out,"STO %02d\n",$cmd - 0x30);break;
			case 0x40:fprintf($out,"+\n");break;
			case 0x41:fprintf($out,"-\n");break;
			case 0x42:fprintf($out,"×\n");break;
			case 0x43:fprintf($out,"÷\n");break;
			case 0x44:fprintf($out,"X<Y?\n");break;
			case 0x45:fprintf($out,"X>Y?\n");break;				
			case 0x46:fprintf($out,"X≤Y?\n");break;				
			case 0x47:fprintf($out,"Σ+\n");break;
			case 0x48:fprintf($out,"Σ-\n");break;				
			case 0x49:fprintf($out,"HMS+\n");break;				
			case 0x4A:fprintf($out,"HMS-\n");break;				
			case 0x4B:fprintf($out,"MOD\n");break;				
			case 0x4C:fprintf($out,"%%\n");break;				
			case 0x4D:fprintf($out,"%%CH\n");break;				
			case 0x4E:fprintf($out,"→REC\n");break;
			case 0x4F:fprintf($out,"→POL\n");break;
			case 0x50:fprintf($out,"LN\n");break;
			case 0x51:fprintf($out,"X↑2\n");break;
			case 0x52:fprintf($out,"SQRT\n");break;
			case 0x53:fprintf($out,"Y↑X\n");break;
			case 0x54:fprintf($out,"+/-\n");break;
			case 0x55:fprintf($out,"E^X\n");break;
			case 0x56:fprintf($out,"LOG\n");break;
			case 0x57:fprintf($out,"10↑X\n");break;
			case 0x58:fprintf($out,"E^X-1\n");break;				
			case 0x59:fprintf($out,"SIN\n");break;
			case 0x5A:fprintf($out,"COS\n");break;
			case 0x5B:fprintf($out,"TAN\n");break;
			case 0x5C:fprintf($out,"ASIN\n");break;
			case 0x5D:fprintf($out,"ACOS\n");break;
			case 0x5E:fprintf($out,"ATAN\n");break;				
			case 0x5F:fprintf($out,"→DEC\n");break;				
			case 0x60:fprintf($out,"1/X\n");break;
			case 0x61:fprintf($out,"ABS\n");break;				
			case 0x62:fprintf($out,"N!\n");break;				
			case 0x63:fprintf($out,"X≠0?\n");break;	
			case 0x64:fprintf($out,"X>0?\n");break;	
			case 0x65:fprintf($out,"LN1+X\n");break;	
			case 0x66:fprintf($out,"X<0?\n");break;					
			case 0x67:fprintf($out,"X=0?\n");break;																				
			case 0x68:fprintf($out,"IP\n");break;
			case 0x69:fprintf($out,"FP\n");break;
			case 0x6A:fprintf($out,"→RAD\n");break;
			case 0x6B:fprintf($out,"→DEG\n");break;
			case 0x6C:fprintf($out,"→HMS\n");break;
			case 0x6D:fprintf($out,"→HR\n");break;
			case 0x6E:fprintf($out,"RND\n");break;				
			case 0x6F:fprintf($out,"→OCT\n");break;				
			case 0x70:fprintf($out,"CLΣ\n");break;
			case 0x71:fprintf($out,"X<>Y\n");break;
			case 0x72:fprintf($out,"PI\n");break;
			case 0x73:fprintf($out,"CLST\n");break;				
			case 0x74:fprintf($out,"R^\n");break;								
			case 0x75:fprintf($out,"R↓\n");break;	
			case 0x76:fprintf($out,"LASTX\n");break;						
			case 0x77:fprintf($out,"CLX\n");break;				
			case 0x78:fprintf($out,"X=Y?\n");break;				
			case 0x79:fprintf($out,"X≠Y?\n");break;				
			case 0x7A:fprintf($out,"SIGN\n");break;				
			case 0x7B:fprintf($out,"X≤0?\n");break;				
			case 0x7C:fprintf($out,"MEAN\n");break;
			case 0x7D:fprintf($out,"SDEV\n");break;
			case 0x7E:fprintf($out,"AVIEW\n");break;				
			case 0x7F:fprintf($out,"CLD\n");break;				
			case 0x80:fprintf($out,"DEG\n");break;
			case 0x81:fprintf($out,"RAD\n");break;
			case 0x82:fprintf($out,"GRAD\n");break;				
			case 0x83:fprintf($out,"ENTER\n");break;				
			case 0x84:fprintf($out,"ENTER\n");break;								
			case 0x85:fprintf($out,"RTN\n");break;
			case 0x86:fprintf($out,"BEEP\n");break;				
			case 0x87:fprintf($out,"CLA\n");break;				
			case 0x88:fprintf($out,"ASHF\n");break;				
			case 0x89:fprintf($out,"PSE\n");break;				
			case 0x8A:fprintf($out,"CLRG\n");break;				
			case 0x8B:fprintf($out,"AOFF\n");break;
			case 0x8C:fprintf($out,"AON\n");break;				
			case 0x8D:fprintf($out,"OFF\n");break;				
			case 0x8E:fprintf($out,"PROMPT\n");break;			
			case 0x8F:fprintf($out,"ADV\n");break;
			case 0x90:reg_thing($in,$out,"RCL");break;	
			case 0x91:reg_thing($in,$out,"STO");break;			
			case 0x92:reg_thing($in,$out,"STO+");break;	
			case 0x92:reg_thing($in,$out,"STO+");break;
			case 0x93:reg_thing($in,$out,"STO-");break;
			case 0x94:reg_thing($in,$out,"STO×");break;
			case 0x95:reg_thing($in,$out,"STO÷");break;												
			case 0x96:reg_thing($in,$out,"ISG");break;	
			case 0x97:reg_thing($in,$out,"DSE");break;
			case 0x98:reg_thing($in,$out,"VIEW");break;
			case 0x99:reg_thing($in,$out,"ΣREG");break;		
			case 0x9A:reg_thing($in,$out,"ASTO");break;
			case 0x9B:reg_thing($in,$out,"ARCL");break;
			case 0x9C:reg_thing($in,$out,"FIX");break;
			case 0x9D:reg_thing($in,$out,"SCI");break;
			case 0x9E:reg_thing($in,$out,"ENG");break;
			case 0x9F:$size = ord(fgetc($in));
				if ( $size <= 0x63 )
					fprintf($out,"TONE %d \n",$size);
				else {
					fprintf($out,"TONE ");
					regstuff($out,$size);
				}
				break;
			case 0xA0:$cmd = ord(fgetc($in));
				switch ($cmd) {
					case 0x61:fprintf($out,"SINH\n");break;
					case 0x62:fprintf($out,"COSH\n");break;
					case 0x63:fprintf($out,"TANH\n");break;
					case 0x64:fprintf($out,"ASINH\n");break;
					case 0x65:fprintf($out,"ATANH\n");break;	
					case 0x66:fprintf($out,"ACOSH\n");break;
					case 0x6F:fprintf($out,"COMB\n");break;
					case 0x70:fprintf($out,"PERM\n");break;
					case 0x71:fprintf($out,"RAN\n");break;						
					case 0x72:fprintf($out,"COMPLEX\n");break;
					case 0x73:fprintf($out,"SEED\n");break;
					case 0x74:fprintf($out,"GAMMA\n");break;
					case 0x9F:fprintf($out,"BEST\n");break;
					case 0xA0:fprintf($out,"EXPF\n");break;
					case 0xA1:fprintf($out,"LINF\n");break;
					case 0xA2:fprintf($out,"LOGF\n");break;
					case 0xA3:fprintf($out,"PWRF\n");break;
					case 0xA4:fprintf($out,"SLOPE\n");break;
					case 0xA5:fprintf($out,"SUM\n");break;
					case 0xA6:fprintf($out,"YINT\n");break;
					case 0xA7:fprintf($out,"CORR\n");break;
					case 0xAA:fprintf($out,"INSR\n");break;						
					case 0xAB:fprintf($out,"DELR\n");break;
					case 0xAE:fprintf($out,"ALLΣ\n");break;
					case 0xA8:fprintf($out,"FCSTX\n");break;
					case 0xA9:fprintf($out,"FCSTY\n");break;
					case 0xAC:fprintf($out,"WMEAN\n");break;
					case 0xAD:fprintf($out,"LINΣ\n");break;
					case 0xE2:fprintf($out,"HEXM\n");break;
					case 0xE3:fprintf($out,"DECM\n");break;
					case 0xE4:fprintf($out,"OCTM\n");break;
					case 0xE5:fprintf($out,"BINM\n");break;						
					case 0xE6:fprintf($out,"BASE+\n");break;
					case 0xE7:fprintf($out,"BASE-\n");break;						
					case 0xE8:fprintf($out,"BASE×\n");break;
					case 0xE9:fprintf($out,"BASE÷\n");break;
					case 0xEA:fprintf($out,"BASE+/-\n");break;					
					default:
						fprintf($out,"ERROR: A0 %x UNKNOWN\n",$cmd);
						break;
				}
				break;
			case 0xA2:$cmd = ord(fgetc($in));
				switch ($cmd) {
					case 0x59:fprintf($out,"POLAR\n");break;
					case 0x5A:fprintf($out,"RECT\n");break;		
					case 0x5B:fprintf($out,"RDX.\n");break;
					case 0x5C:fprintf($out,"RDX,\n");break;	
					case 0x5D:fprintf($out,"ALL\n");break;
					case 0x5E:fprintf($out,"MENU\n");break;
					case 0x5F:fprintf($out,"X≥0?\n");break;
					case 0x60:fprintf($out,"X≥Y?\n");break;												
					case 0x62:fprintf($out,"CLKEYS\n");break;
					case 0x63:fprintf($out,"KEYASN\n");break;		
					case 0x64:fprintf($out,"LCLBL\n");break;
					case 0x65:fprintf($out,"REAL?\n");break;					
					case 0x66:fprintf($out,"MAT?\n");break;
					case 0x67:fprintf($out,"CPX?\n");break;					
					case 0x68:fprintf($out,"STR?\n");break;						
					case 0x6A:fprintf($out,"CPXRES\n");break;
					case 0x6B:fprintf($out,"REALRES\n");break;
					case 0x6C:fprintf($out,"EXITALL\n");break;
					case 0x6D:fprintf($out,"CLMENU\n");break;
					case 0x6E:fprintf($out,"GETKEY\n");break;
					case 0x6F:fprintf($out,"CUSTOM\n");break;					
					case 0x70:fprintf($out,"OLD\n");break;
					default:fprintf($out,"ERROR: A2 %x UNKNOWN\n",$cmd);break;
				}
				break;
			case 0xA5:$cmd = ord(fgetc($in));
				switch ($cmd) {
					case 0x87:fprintf($out,"NOT\n");break;
					case 0x88:fprintf($out,"AND\n");break;					
					case 0x89:fprintf($out,"OR\n");break;					
					case 0x8A:fprintf($out,"XOR\n");break;					
					case 0x8B:fprintf($out,"ROTXY\n");break;					
					case 0x8C:fprintf($out,"BIT?\n");break;
					default:fprintf($out,"ERROR: A5 %x UNKNOWN\n",$cmd);break;
				}
				break;
			case 0xA6:$cmd = ord(fgetc($in));
				switch ($cmd) {
					case 0x31:fprintf($out,"AIP\n");break;
					case 0x41:fprintf($out,"ALENG\n");break;
					case 0x46:fprintf($out,"AROT\n");break;
					case 0x47:fprintf($out,"ATOX\n");break;	
					case 0x5C:fprintf($out,"POSA\n");break;											
					case 0x6F:fprintf($out,"XTOA\n");break;
					case 0x78:fprintf($out,"ΣREG?\n");break;
					case 0xC9:fprintf($out,"TRANS\n");break;
					case 0xCA:fprintf($out,"CROSS\n");break;
					case 0xCB:fprintf($out,"DOT\n");break;
					case 0xCC:fprintf($out,"DET\n");break;
					case 0xCD:fprintf($out,"UVEC\n");break;
					case 0xCE:fprintf($out,"INVRT\n");break;
					case 0xCF:fprintf($out,"FNRM\n");break;
					case 0xD0:fprintf($out,"RSUM\n");break;
					case 0xD1:fprintf($out,"R<>R\n");break;							
					case 0xD2:fprintf($out,"I+\n");break;	
					case 0xD3:fprintf($out,"I-\n");break;		
					case 0xD4:fprintf($out,"J+\n");break;																	
					case 0xD5:fprintf($out,"J-\n");break;		
					case 0xD6:fprintf($out,"STOEL\n");break;
					case 0xD7:fprintf($out,"RCLEL\n");break;
					case 0xD8:fprintf($out,"STOIJ\n");break;
					case 0xD9:fprintf($out,"RCLIJ\n");break;
					case 0xDA:fprintf($out,"NEWMAT\n");break;
					case 0xDB:fprintf($out,"OFF\n");break;
					case 0xDC:fprintf($out,"←\n");break;		
					case 0xDD:fprintf($out,"→\n");break;					
					case 0xDE:fprintf($out,"^\n");break;
					case 0xDF:fprintf($out,"↓\n");break;																								
					case 0xE1:fprintf($out,"EDIT\n");break;
					case 0xE2:fprintf($out,"WRAP\n");break;	
					case 0xE3:fprintf($out,"GROW\n");break;					
					case 0xE7:fprintf($out,"DIM?\n");break;
					case 0xE8:fprintf($out,"GETM\n");break;
					case 0xE9:fprintf($out,"PUTM\n");break;
					case 0xEA:fprintf($out,"[MIN]\n");break;	
					case 0xEB:fprintf($out,"[MAX]\n");break;
					case 0xEC:fprintf($out,"[FIND]\n");break;						
					case 0xED:fprintf($out,"RNRM\n");break;
					default:fprintf($out,"ERROR: A6 %x UNKNOWN\n",$cmd);break;
				}
				break;
			case 0xA7:$cmd = ord(fgetc($in));
				switch ($cmd) {
					case 0x48:fprintf($out,"PRA\n");break;	
					case 0x52:fprintf($out,"PRΣ\n");break;							
					case 0x53:fprintf($out,"PRSTK\n");break;	
					case 0x54:fprintf($out,"PRX\n");break;						
					case 0x5B:fprintf($out,"MAN\n");break;	
					case 0x5D:fprintf($out,"TRACE\n");break;
					case 0x5E:fprintf($out,"PRON\n");break;	
					case 0x5F:fprintf($out,"PROFF\n");break;								
					case 0x60:fprintf($out,"DELAY\n");break;
					case 0x61:fprintf($out,"PRUSR\n");break;						
					case 0x62:fprintf($out,"PRLCD\n");break;						
					case 0x63:fprintf($out,"CLLCD\n");break;
					case 0x64:fprintf($out,"AGRAPH\n");break;
					case 0x65:fprintf($out,"PIXEL\n");break;						
					case 0x5C:fprintf($out,"NORM\n");break;
					default:fprintf($out,"ERROR: A7 %x UNKNOWN\n",$cmd);break;
				}
				break;
			case 0xA8:reg_thing($in,$out,"SF");break;
			case 0xA9:reg_thing($in,$out,"CF");break;
			case 0xAA:reg_thing($in,$out,"FS?C");break;
			case 0xAB:reg_thing($in,$out,"FC?C");break;
			case 0xAC:reg_thing($in,$out,"FS?");break;
			case 0xAD:reg_thing($in,$out,"FC?");break;	
			case 0xAE:$flag = ord(fgetc($in));
				if ( $flag >= 0x80 ) {
					fprintf($out,"XEQ IND ");
					$flag = $flag - 0x80;
				}
				else 
					fprintf($out,"GTO IND ");
				gtoregstuff($out,$flag);
				break;	
			case 0xB1:	// GTO local
			case 0xB2:
			case 0xB3:
			case 0xB4:
			case 0xB5:
			case 0xB6:
			case 0xB7:
			case 0xB8:
			case 0xB9:
			case 0xBA:
			case 0xBB:
			case 0xBC:
			case 0xBD:
			case 0xBE:
			case 0xBF:$newcmd = ord(fgetc($in));
				switch ($newcmd) {
					case 0x0:fprintf($out,"GTO %02d\n",$cmd - 0xB1);break;
					default:fprintf($out,"ERROR: %x %x UNKNOWN\n",$cmd,$newcmd);break;
				}
				break;
			case 0xC0:	// LBL or END
			case 0xCA:
				$ch = fgetc($in);	// Discard 00
				$len = ord(fgetc($in));
				if ( $len == 0xd )
					fprintf($out,"END\n");
				else {
					fprintf($out,"LBL ");
					$ch = fgetc($in);	// Discard 00
					dumpn($in,$out,fixlen($len),true);
				}
				break;		
			case 0xCE:reg_thing($in,$out,"X<>");break;	
			case 0xCF:$label = ord(fgetc($in));
				if ( $label >= 0x7B && $label <= 0x7F )
					fprintf($out,"LBL %c\n",$label-0x1A);
				else if ( $label >= 0x66 && $label <= 0x6F )
					fprintf($out,"LBL %c\n",$label-0x25);
				else
					fprintf($out,"LBL %02d\n",$label);
				break;
			case 0xD0:$newcmd = ord(fgetc($in));
				switch ($newcmd) {
					case 0x00:$label = ord(fgetc($in));
						if ( $label >= 0x7B && $label <= 0x7F )
							fprintf($out,"GTO %c\n",$label-0x1A);
						else if ( $label >= 0x66 && $label <= 0x6F )
							fprintf($out,"GTO %c\n",$label-0x25);
						else
							fprintf($out,"GTO %02d\n",$label);
						break;
					default:fprintf($out,"ERROR: %x %x UNKNOWN\n",$cmd,$newcmd);break;
				}
				break;
			case 0xE0:$newcmd = ord(fgetc($in));
				switch ($newcmd) {
					case 0x00:$label = ord(fgetc($in));
						if ( $label >= 0x7B && $label <= 0x7F )
							fprintf($out,"XEQ %c\n",$label-0x1A);
						else if ( $label >= 0x66 && $label <= 0x6F )
							fprintf($out,"XEQ %c\n",$label-0x25);
						else
							fprintf($out,"XEQ %02d\n",$label);
						break;
					default:fprintf($out,"ERROR: %x %x UNKNOWN\n",$cmd,$newcmd);break;
				}
				break;		
			case 0xF1:$size = ord(fgetc($in));
				switch ($size) {
					case 0xD5:fprintf($out,"FIX 10\n");break;
					case 0xE5:fprintf($out,"FIX 11\n");break;
					case 0xD6:fprintf($out,"SCI 10\n");break;
					case 0xE6:fprintf($out,"SCI 11\n");break;
					case 0xD7:fprintf($out,"ENG 10\n");break;
					case 0xE7:fprintf($out,"ENG 11\n");break;
				}
				break;	
			case 0x0:fprintf($out,"\n");break;
			default :if ( $cmd >= 0xF1 && $cmd <= 0xFF ){
					$ch = fgetc($in);
					$newcmd = ord($ch);
					switch ($newcmd ) {
						case 0x80:alpha_thing($in,$out,"VIEW",$cmd);break;	
						case 0x81:alpha_thing($in,$out,"STO",$cmd);break;
						case 0x82:alpha_thing($in,$out,"STO+",$cmd);break;
						case 0x83:alpha_thing($in,$out,"STO-",$cmd);break;
						case 0x84:alpha_thing($in,$out,"STO×",$cmd);break;
						case 0x85:alpha_thing($in,$out,"STO÷",$cmd);break;
						case 0x86:alpha_thing($in,$out,"X<>",$cmd);break;														
						case 0x87:alpha_thing($in,$out,"INDEX",$cmd);break;
						case 0x88:alpha_thing($in,$out,"VIEW IND",$cmd);break;	
						case 0x89:alpha_thing($in,$out,"STO IND",$cmd);break;	
						case 0x8A:alpha_thing($in,$out,"STO+ IND",$cmd);break;
						case 0x8B:alpha_thing($in,$out,"STO- IND",$cmd);break;	
						case 0x8C:alpha_thing($in,$out,"STO× IND",$cmd);break; 
						case 0x8D:alpha_thing($in,$out,"STO÷ IND",$cmd);break;								
						case 0x8E:alpha_thing($in,$out,"X<> IND",$cmd);break;																																													
						case 0x8F:alpha_thing($in,$out,"INDEX IND",$cmd);break;				
						case 0x90:alpha_thing($in,$out,"MVAR",$cmd);break;	
						case 0x91:alpha_thing($in,$out,"RCL",$cmd);break;		
						case 0x92:alpha_thing($in,$out,"RCL+",$cmd);break;									
						case 0x93:alpha_thing($in,$out,"RCL-",$cmd);break;	
						case 0x94:alpha_thing($in,$out,"RCL×",$cmd);break;
						case 0x95:alpha_thing($in,$out,"RCL÷",$cmd);break;																								
						case 0x96:alpha_thing($in,$out,"ISG",$cmd);break;						
						case 0x97:alpha_thing($in,$out,"DSE",$cmd);break;
						case 0x99:alpha_thing($in,$out,"RCL IND",$cmd);break;
						case 0x9A:alpha_thing($in,$out,"RCL+ IND",$cmd);break;								
						case 0x9B:alpha_thing($in,$out,"RCL- IND",$cmd);break;	
						case 0x9C:alpha_thing($in,$out,"RCL× IND",$cmd);break;	
						case 0x9D:alpha_thing($in,$out,"RCL÷ IND",$cmd);break;																						
						case 0x9E:alpha_thing($in,$out,"ISG IND",$cmd);break;							
						case 0x9F:alpha_thing($in,$out,"DSE IND",$cmd);break;
						case 0xA8:alpha_thing($in,$out,"SF IND",$cmd);break;							
						case 0xA9:alpha_thing($in,$out,"CF IND",$cmd);break;
						case 0xAA:alpha_thing($in,$out,"FS?C IND",$cmd);break;	
						case 0xAB:alpha_thing($in,$out,"FC?C IND",$cmd);break;																
						case 0xAC:alpha_thing($in,$out,"FS? IND",$cmd);break;
						case 0xAD:alpha_thing($in,$out,"FC? IND",$cmd);break;										
						case 0xAE:alpha_thing($in,$out,"GTO IND",$cmd);break;
						case 0xAF:alpha_thing($in,$out,"XEQ IND",$cmd);break;																			
						case 0xB0:alpha_thing($in,$out,"CLV",$cmd);break;
						case 0xB1:alpha_thing($in,$out,"PRV",$cmd);break;								
						case 0xB2:alpha_thing($in,$out,"ASTO",$cmd);break;
						case 0xB3:alpha_thing($in,$out,"ARCL",$cmd);break;
						case 0xB4:alpha_thing($in,$out,"PGMINT",$cmd);break;
						case 0xB5:alpha_thing($in,$out,"PGMSLV",$cmd);break;
						case 0xB6:alpha_thing($in,$out,"INTEG",$cmd);break;
						case 0xB7:alpha_thing($in,$out,"SOLVE",$cmd);break;	
						case 0xB8:alpha_thing($in,$out,"CLV IND",$cmd);break;	
						case 0xB9:alpha_thing($in,$out,"PRV IND",$cmd);break;							
						case 0xBA:alpha_thing($in,$out,"ASTO IND",$cmd);break;		
						case 0xBB:alpha_thing($in,$out,"ARCL IND",$cmd);break;		
						case 0xBC:alpha_thing($in,$out,"PGMINT IND",$cmd);break;							
						case 0xBD:alpha_thing($in,$out,"PGMSLV IND",$cmd);break;							
						case 0xBE:alpha_thing($in,$out,"INTEG IND",$cmd);break;
						case 0xBF:alpha_thing($in,$out,"SOLVE IND",$cmd);break;										
						case 0xC0:fprintf($out,"ASSIGN ");
							dumpn($in,$out,fixlen($cmd)-1,false);
							$to = ord(fgetc($in));
							fprintf($out," TO %02d\n",$to+1);
							break;		
						case 0xC1:alpha_thing($in,$out,"VARMENU",$cmd);break;										
						case 0xC2:$key = ord(fgetc($in));
							fprintf($out,"KEY %d XEQ ",$key);
							dumpn($in,$out,fixlen($cmd)-1,true);
							break;											
						case 0xC3:$key = ord(fgetc($in));
							fprintf($out,"KEY %d GTO ",$key);
							dumpn($in,$out,fixlen($cmd)-1,true);
							break;			
						case 0xC4:alpha_thing($in,$out,"DIM",$cmd);break;
						case 0xC5:alpha_thing($in,$out,"INPUT",$cmd);break;
						case 0xC6:alpha_thing($in,$out,"EDITN",$cmd);break;
						case 0xC9:alpha_thing($in,$out,"VARMENU IND",$cmd);break;									
						case 0xCA:$key = ord(fgetc($in));
							fprintf($out,"KEY %d XEQ IND ",$key);
							dumpn($in,$out,fixlen($cmd)-1,true);
							break;											
						case 0xCB:$key = ord(fgetc($in));
							fprintf($out,"KEY %d GTO IND ",$key);
							dumpn($in,$out,fixlen($cmd)-1,true);
							break;																		
						case 0xCC:alpha_thing($in,$out,"DIM IND",$cmd);break;
						case 0xCD:alpha_thing($in,$out,"INPUT IND",$cmd);break;
						case 0xCE:alpha_thing($in,$out,"EDITN IND",$cmd);break;
						case 0xD0:alpha_thing($in,$out,"INPUT",$cmd);break;
						case 0xD1:reg_thing($in,$out,"RCL+");break;		
						case 0xD2:reg_thing($in,$out,"RCL-");break;	
						case 0xD3:reg_thing($in,$out,"RCL×");break;
				 		case 0xD4:reg_thing($in,$out,"RCL÷");break;																																									
						case 0xD8:reg_thing($in,$out,"CLV");break;	
						case 0xD9:reg_thing($in,$out,"PRV");break;										
						case 0xDA:reg_thing($in,$out,"INDEX");break;		
						case 0xDB:alpha_thing($in,$out,"ΣREG IND",$cmd);break;																	
						case 0xDC:alpha_thing($in,$out,"FIX IND",$cmd);break;	
						case 0xDD:alpha_thing($in,$out,"SCI IND",$cmd);break;				
						case 0xDE:alpha_thing($in,$out,"ENG IND",$cmd);break;	
						case 0xDF:alpha_thing($in,$out,"TONE IND",$cmd);break;								
						case 0xE2:$key = ord(fgetc($in));
							fprintf($out,"KEY %d XEQ ",$key);
							$c = ord(fgetc($in));
							regstuff($out,$c);
							break;										
						case 0xE3:$key = ord(fgetc($in));
							fprintf($out,"KEY %d GTO ",$key);
							$c = ord(fgetc($in));
							regstuff($out,$c);
							break;		
						case 0xE8:reg_thing($in,$out,"PGMINT");break;	
						case 0xE9:reg_thing($in,$out,"PGMSLV");break;																									
						case 0xEA:reg_thing($in,$out,"INTEG");break;	
						case 0xEB:reg_thing($in,$out,"SOLVE");break;															
						case 0xEC:reg_thing($in,$out,"DIM");break;		
						case 0xEE:reg_thing($in,$out,"INPUT");break;								
						case 0xEF:reg_thing($in,$out,"EDITN");break;									
						case 0xF0:reg_thing($in,$out,"CLP");break;
						case 0xF7:fprintf($out,"SIZE ");
							$hi = ord(fgetc($in));
							$lo = ord(fgetc($in));
							$size = $hi * 256 + $lo;
							fprintf($out,"$size\n");
							break;	
						case 0xF8:reg_thing($in,$out,"VARMENU");break;		
						default:fprintf($out,"\"");
							fprintf($out,"%s",chr($newcmd));
							dumpn($in,$out,fixlen($cmd)-1,false);
							break;
					}
				}
				else {	// Assume it's a character or number
					if ( $cmd < 0x41 ) {
						switch ($cmd) {
							case 0x1A:fprintf($out,".");break;
							case 0x1B:fprintf($out,"E");break;
							case 0x1C:fprintf($out,"-");break;
							default:fprintf($out,"%s",chr($cmd+0x20));break;
						}
					}
					else
						fprintf($out,"%s",chr($cmd));
					if ( $cmd != 0x00 )
						$eol = false;
				}
		}

	}

?>
Attachments
stress.raw
(1.31 KiB) Downloaded 181 times
Steve

DM32 SN: 00316
DM41X SN: 00854
DM42 SN: 03223


HP11C, HP12C, HP15C, HP16C, HP25, HP32S, HP33C, HP41CV, HP46, HP65
User avatar
henrik
Posts: 18
Joined: Wed Jun 07, 2023 1:18 am
Location: Germany
Contact:

Re: DM42 Decoder

Post by henrik »

Hi Steve,

I lately found your DM42-Decoder - this is very interesting, thanks for sharing!
To be able to write such a program, you must have some specification for converting .raw<->.txt.
Could you give me a hint on where to find such specification?

Many thanks and best regards -- Henrik
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: DM42 Decoder

Post by Thomas Okken »

hsilop wrote:
Fri Jun 09, 2023 4:44 am
Here is a DM42 Decoder. It can decode the modified stress program attached.
Now that you mention it, the stress program on my web site is way out of date, since it only covers the HP-42S instruction set.
I just uploaded a new version, including all the additional functions from Free42 and Plus42.
henrik wrote:
Mon Oct 30, 2023 7:20 pm
To be able to write such a program, you must have some specification for converting .raw<->.txt.
Could you give me a hint on where to find such specification?
There isn't one, other than the Free42 and Plus42 source code. Specifically, the core_import_programs() and export_hp42s() functions in core_main.cc convert from raw to the in-memory storage format and back. The conversions use several tables: hp42tofree42 and hp42ext in core_main.cc, and cmd_array in core_tables.cc.

The conversion from the internal format to text is easy, because that's basically just PRP. The conversion from text to the internal format is more complicated; this is handled by paste_programs() in core_main.cc.

It's probably easier to just compare a hex dump of my updated stress.raw with stress.txt (https://thomasokken.com/free42/42progs/).
User avatar
henrik
Posts: 18
Joined: Wed Jun 07, 2023 1:18 am
Location: Germany
Contact:

Re: DM42 Decoder

Post by henrik »

Thomas Okken wrote:
Thu Dec 14, 2023 2:30 pm
henrik wrote:
Mon Oct 30, 2023 7:20 pm
To be able to write such a program, you must have some specification for converting .raw<->.txt.
Could you give me a hint on where to find such specification?
There isn't one, other than the Free42 and Plus42 source code. Specifically, the core_import_programs() and export_hp42s() functions in core_main.cc convert from raw to the in-memory storage format and back. The conversions use several tables: hp42tofree42 and hp42ext in core_main.cc, and cmd_array in core_tables.cc.

The conversion from the internal format to text is easy, because that's basically just PRP. The conversion from text to the internal format is more complicated; this is handled by paste_programs() in core_main.cc.

It's probably easier to just compare a hex dump of my updated stress.raw with stress.txt (https://thomasokken.com/free42/42progs/).
Dear Thomas, many thanks for this info - and of course for your great work! Regards -- Henrik
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: DM42 Decoder

Post by Thomas Okken »

I posted new text<->raw conversion tools, raw2txt and txt2raw. They are under Additional Downloads on the Free42 and Plus42 home pages.

These tools are based on an idea by Thomas Klemm, to simply use the Free42 / Plus42 core itself to do the conversions. The resulting executables are a bit large, but the big advantage is that the coding effort was negligible, and keeping the tools in sync with the apps is a simple matter of rebuilding when needed.
Post Reply