1 /* 2 * TilEm II 3 * 4 * Copyright (c) 2011 Benjamin Moody 5 * 6 * This program is free software: you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation, either version 3 of the 9 * License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 enum { 21 TI81_SLOT_AUTO = -1, 22 TI81_SLOT_0, TI81_SLOT_1, TI81_SLOT_2, TI81_SLOT_3, TI81_SLOT_4, 23 TI81_SLOT_5, TI81_SLOT_6, TI81_SLOT_7, TI81_SLOT_8, TI81_SLOT_9, 24 TI81_SLOT_A, TI81_SLOT_B, TI81_SLOT_C, TI81_SLOT_D, TI81_SLOT_E, 25 TI81_SLOT_F, TI81_SLOT_G, TI81_SLOT_H, TI81_SLOT_I, TI81_SLOT_J, 26 TI81_SLOT_K, TI81_SLOT_L, TI81_SLOT_M, TI81_SLOT_N, TI81_SLOT_O, 27 TI81_SLOT_P, TI81_SLOT_Q, TI81_SLOT_R, TI81_SLOT_S, TI81_SLOT_T, 28 TI81_SLOT_U, TI81_SLOT_V, TI81_SLOT_W, TI81_SLOT_X, TI81_SLOT_Y, 29 TI81_SLOT_Z, TI81_SLOT_THETA 30 }; 31 32 #define TI81_SLOT_MAX TI81_SLOT_THETA 33 34 typedef struct _TI81ProgInfo { 35 int slot; /* program slot number */ 36 int size; /* size of program contents */ 37 dword addr; /* address of program contents */ 38 byte name[8]; /* program name, tokens */ 39 } TI81ProgInfo; 40 41 typedef struct _TI81Program { 42 TI81ProgInfo info; 43 byte *data; 44 } TI81Program; 45 46 /* Error codes */ 47 enum { 48 TI81_ERR_FILE_IO = 1, /* File I/O error */ 49 TI81_ERR_INVALID_FILE, /* PRG file is invalid */ 50 TI81_ERR_MEMORY, /* Not enough memory to load program */ 51 TI81_ERR_SLOTS_FULL, /* No free program slots */ 52 TI81_ERR_BUSY, /* Calculator is busy and unable 53 to load/save programs */ 54 TI81_ERR_INTERNAL 55 }; 56 57 /* Create a new TI81Program with the given size. */ 58 TI81Program * ti81_program_new(int size) 59 TILEM_ATTR_MALLOC; 60 61 /* Free a TI81Program. */ 62 void ti81_program_free(TI81Program *prgm); 63 64 /* Get information about the program in the given slot. */ 65 int ti81_get_program_info(const TilemCalc *calc, int slot, TI81ProgInfo *info); 66 67 /* Retrieve a program from calculator memory. Free the resulting 68 program with ti81_program_free() when you're done with it. */ 69 int ti81_get_program(const TilemCalc *calc, int slot, TI81Program **prgm); 70 71 /* Load a program into calculator memory. */ 72 int ti81_load_program(TilemCalc *calc, const TI81Program *prgm); 73 74 /* Read a program from a PRG file. Free the resulting program with 75 ti81_program_free() when you're done with it. */ 76 int ti81_read_prg_file(FILE *f, TI81Program **prgm); 77 78 /* Write a program to a PRG file. */ 79 int ti81_write_prg_file(FILE *f, const TI81Program *prgm); 80 81 /* Convert program slot number into a UTF-8 string. Free the result 82 with tilem_free() when you're done with it. */ 83 char * ti81_program_slot_to_string(int slot) 84 TILEM_ATTR_MALLOC; 85 86 /* Convert program name to a UTF-8 string. Free the result with 87 tilem_free() when you're done with it. */ 88 char * ti81_program_name_to_string(const byte *prgname) 89 TILEM_ATTR_MALLOC; 90