123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- /* $Id$
- * MegaZeux
- *
- * Copyright (C) 1996 Greg Janson
- * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
- //Code to edit character sets and switch between ega 14 point mode and
- //vga 16 point mode
- //SMZX commented out -Koji
- #include "meminter.h"
- #include "charset.h"
- #include "string.h"
- #include <stdio.h>
- #include <dos.h>
- #include "egacode.h"
- //Current set- No reading of characters ever neccesary!
- unsigned char far *curr_set;//Size- 14*256 bytes
- static volatile int need_update=1;
- //Segment of character set memory
- #define CS_Seg 0xb800
- //Offset of character set 0 (the only one used)
- #define CS_Offs 0x0000
- //Pointer to character set memory, as unsigned char far
- #define CS_Ptr ((unsigned char far *)MK_FP(CS_Seg,CS_Offs))
- //Enter 14-byte high character mode and reset character sets
- //(EGA native text mode)
- void ega_14p_mode(void) {
- asm {
- mov ax,1201h
- mov bl,30h
- int 10h
- mov ax,0003h
- int 10h
- }
- }
- /*void smzx_14p_mode(void)
- {
- asm {
- mov ax,1201h
- mov bl,30h
- int 10h
- mov ax,0003h
- int 10h
- mov dx,03C0h
- mov al,10h
- out dx,al
- mov al,4Ch
- out dx,al
- }
- } */
- //Enter 16-byte high character mode and reset character sets
- //(VGA native text mode)
- void vga_16p_mode(void) {
- asm {
- mov ax,1202h
- mov bl,30h
- int 10h
- mov ax,0003h
- int 10h
- }
- }
- //Access the character set part of the graphics memory (internal function)
- void _access_char_sets(void) {
- asm {
- mov al,5
- mov dx,3ceh
- out dx,al // outportb(0x3ce,5)
- mov al,0
- mov dx,3cfh
- out dx,al // outportb(0x3cf,0)
- mov al,6
- mov dx,3ceh
- out dx,al // outportb(0x3ce,6)
- mov al,0ch
- mov dx,3cfh
- out dx,al // outportb(0x3cf,0xc)
- mov al,4
- mov dx,3c4h
- out dx,al // outportb(0x3c4,4)
- mov al,6
- mov dx,3c5h
- out dx,al // outportb(0x3c5,6)
- mov al,2
- mov dx,3c4h
- out dx,al // outportb(0x3c4,2)
- mov al,4
- mov dx,3c5h
- out dx,al // outportb(0x3c5,4)
- mov dx,3ceh
- out dx,al // outportb(0x3ce,4)
- mov al,2
- mov dx,3cfh
- out dx,al // outportb(0x3cf,2)
- }
- }
- //Access the regular text memory (internal function)
- void _access_text(void) {
- asm {
- mov al,5
- mov dx,3ceh
- out dx,al // outportb(0x3ce,5)
- mov al,10h
- mov dx,3cfh
- out dx,al // outportb(0x3cf,0x10)
- mov al,6
- mov dx,3ceh
- out dx,al // outportb(0x3ce,6)
- mov al,0eh
- mov dx,3cfh
- out dx,al // outportb(0x3cf,0xe)
- mov al,4
- mov dx,3c4h
- out dx,al // outportb(0x3c4,4)
- mov al,2
- mov dx,3c5h
- out dx,al // outportb(0x3c5,2)
- mov dx,3c4h
- out dx,al // outportb(0x3c4,2)
- mov al,3
- mov dx,3c5h
- out dx,al // outportb(0x3c5,3)
- mov al,4
- mov dx,3ceh
- out dx,al // outportb(0x3ce,4)
- mov al,0
- mov dx,3cfh
- out dx,al // outportb(0x3cf,0)
- }
- }
- //Copies the set in memory (curr_set) to the real set in graphics memory
- void ec_update_set(void) {
- int remaining;
- unsigned char far *charac=CS_Ptr;
- unsigned char far *cset=curr_set;
- _access_char_sets();
- for ( remaining = 256 ; remaining
- ; remaining--, charac += 32, cset += 14 )
- {
- mem_cpy(charac, cset, 14);
- }
- _access_text();
- need_update = 0;
- }
- void ec_update_set_if_needed(void) {
- if (need_update) ec_update_set();
- }
- //Changes one byte of one character and updates it
- void ec_change_byte(int chr,int byte,int new_value) {
- unsigned char far *charac=CS_Ptr;
- curr_set[chr*14+byte]=new_value;
- _access_char_sets();
- charac[(chr<<5)+byte]=new_value;
- _access_text();
- }
- //Changes one entire 14-byte character and updates it
- void ec_change_char(int chr, unsigned char far *matrix) {
- unsigned char far *charac=CS_Ptr;
- mem_cpy(curr_set+chr*14, matrix, 14);
- _access_char_sets();
- mem_cpy(charac+(chr<<5), matrix, 14);
- _access_text();
- }
- //Changes one byte of one character WITHOUT updating it
- void ec_change_byte_nou(int chr,int byte,int new_value) {
- curr_set[chr*14+byte]=new_value;
- need_update = 1;
- }
- //Changes one entire 14-byte character WITHOUT updating it
- void ec_change_char_nou(int chr,unsigned char far *matrix) {
- mem_cpy(curr_set+chr*14, matrix, 14);
- need_update = 1;
- }
- //Reads one byte of a character
- int ec_read_byte(int chr,int byte) {
- return curr_set[chr*14+byte];
- }
- //Reads an entire 14-byte character
- void ec_read_char(int chr,unsigned char far *matrix) {
- mem_cpy(matrix, curr_set+chr*14, 14);
- }
- //Initialization function. Call AFTER setting mode with ega_14p.
- //Copies current set to curr_set and insures set 0 is activated.
- //Also copies current set to ascii_set. Also runs memory init, returns
- //non-0 for error.
- char ec_init(void) {
- curr_set=(unsigned char far *)farmalloc(3584);
- if(curr_set==NULL) return -1;
- //Copy default mzx to current and update
- mem_cpy((signed char far *)curr_set,
- (signed char far *)default_mzx_char_set, 3584);
- ec_update_set();
- //Done!
- return 0;
- }
- //Call upon exit to free memory
- void ec_exit(void) {
- if(curr_set!=NULL) farfree(curr_set);
- }
- //Save a character set to disk
- char ec_save_set(char far *filename) {
- FILE *fp;
- fp=fopen(filename,"wb");
- if(fp==NULL) return -1;
- fwrite(curr_set,14,256,fp);
- fclose(fp);
- return 0;
- }
- //Load a character set from disk
- char ec_load_set_nou(char far *filename) {
- FILE *fp;
- fp=fopen(filename,"rb");
- if(fp==NULL) return -1;
- fread(curr_set,14,256,fp);
- fclose(fp);
- need_update = 1;
- return 0;
- }
- char ec_load_set(char far *filename) {
- char status;
- status = ec_load_set_nou(filename);
- if (!status) ec_update_set();
- return status;
- }
- //Loads a character set directly from memory (stil 3584 bytes)
- void ec_mem_load_set(unsigned char far *chars) {
- mem_cpy((signed char far *)curr_set,(signed char far *)chars,3584);
- ec_update_set();
- }
- //Loads in the default set (Megazeux)
- void ec_load_mzx(void) {
- ec_mem_load_set(default_mzx_char_set);
- }
|