/* * makealpha.java * Make a pdb file for use with Learn Alpha. * Usage: java makealpha character-file * * Ken Shirriff shirriff@righto.com */ import java.io.*; import java.util.*; public class makealpha { static String namestr; public static void main(String args[]) { if (args.length != 1) { System.out.println("Usage: makealpha name"); Runtime.getRuntime().exit(-1); } try { String tmpfile = "tmp"; readfile(args[0], tmpfile); byte name[] = new byte[32]; short attributes=(short)0x8000; short version=1; int creationDate=0xb08823ad; int modificationDate=0xb08823ad; int lastBackupDate=0xb08823ad; int modificationNumber=1; int appInfoID=0; int sortInfoID=0; byte type[] = {'D','a','t','a'}; byte creator[] = {'K','S','l','a'}; int uniqueIDSeed=0; int l = namestr.length(); namestr.getBytes(0, l, name, 0); name[l] = '\0'; String outfile = namestr+".pdb"; System.out.println("Writing to "+outfile); short numRecords = 1; DataOutputStream os = new DataOutputStream(new FileOutputStream(outfile)); int offset = 80+numRecords*8; // DatabaseHdrType os.write(name); os.writeShort(attributes); os.writeShort(version); os.writeInt(creationDate); os.writeInt(modificationDate); os.writeInt(lastBackupDate); os.writeInt(modificationNumber); os.writeInt(appInfoID); os.writeInt(sortInfoID); os.write(type); os.write(creator); os.writeInt(uniqueIDSeed); // RecordListType int nextRecordListID = 0; os.writeInt(nextRecordListID); os.writeShort(numRecords); for (int i=0; i>16)); // uniqueID os.writeByte((byte)(i>>8)); // uniqueID os.writeByte((byte)(i>>0)); // uniqueID } os.writeShort(0); // pad for (int i=0; i ysize) { ysize = ycnt; } break; } else if (line.length() > xsize) { xsize = line.length(); } } } is.close(); is = new DataInputStream(new FileInputStream(inname)); // File format: // 1234 // number of entries // xsize // ysize // charsize // n characters: each one ysize lines of charsize 2-byte chars // n zero-terminated strings. os.writeInt(1234); os.writeInt(n); chars = ((xsize+15)>>4)<<1; os.writeInt(xsize); os.writeInt(ysize); os.writeInt(chars); System.out.println(""+xsize+" "+ysize+" "+chars); is.readLine(); // Discard the title line for (int i=0;i= mapline.length()) { break; } else if (mapline.charAt(x) == '*') { line[x>>3] |= 1<<(7-(x&7)); } else if (mapline.charAt(x) == '.') { } else { throw new Exception("Bad bitmap line "+mapline); } } os.write(line); } byte line[] = new byte[chars]; for (; y