60
60
#define RINVALID_INDEX 0x30
61
61
62
62
#define JEGA_PATH_BIOS "roms/video/jega/JEGABIOS.BIN"
63
+ #define IF386_PATH_VBIOS "roms/video/jega/OKI_IF386SX_VBIOS.bin"
63
64
#define JEGA_PATH_FONTDBCS "roms/video/jega/JPNZN16X.FNT"
64
65
#define SBCS19_FILESIZE (256 * 19 * 2) /* 8 x 19 x 256 chr x 2 pages */
65
66
#define DBCS16_CHARS 0x2c10
@@ -137,7 +138,8 @@ typedef struct {
137
138
uint16_t end ;
138
139
} fontx_tbl ;
139
140
140
- static uint32_t pallook64 [256 ];
141
+ extern uint32_t pallook16 [256 ];
142
+ extern uint32_t pallook64 [256 ];
141
143
static bool is_SJIS_1 (uint8_t chr ) { return (chr >= 0x81 && chr <= 0x9f ) || (chr >= 0xe0 && chr <= 0xfc ); }
142
144
static bool is_SJIS_2 (uint8_t chr ) { return (chr >= 0x40 && chr <= 0x7e ) || (chr >= 0x80 && chr <= 0xfc ); }
143
145
@@ -615,30 +617,35 @@ LoadFontxFile(const char *fn, void *priv)
615
617
return 0 ;
616
618
}
617
619
618
- static void *
619
- jega_init ( const device_t * info )
620
+ static void
621
+ jega_commoninit ( void * priv )
620
622
{
621
- jega_t * jega = calloc (1 , sizeof (jega_t ));
622
-
623
- rom_init (& jega -> bios_rom , JEGA_PATH_BIOS , 0xc0000 , 0x8000 , 0x7fff , 0 , 0 );
624
- memset (& jega -> jfont_dbcs_16 , 0 , DBCS16_FILESIZE );
625
- LoadFontxFile (JEGA_PATH_FONTDBCS , jega );
626
-
623
+ jega_t * jega = (jega_t * ) priv ;
627
624
for (int c = 0 ; c < 256 ; c ++ ) {
628
625
pallook64 [c ] = makecol32 (((c >> 2 ) & 1 ) * 0xaa , ((c >> 1 ) & 1 ) * 0xaa , (c & 1 ) * 0xaa );
629
626
pallook64 [c ] += makecol32 (((c >> 5 ) & 1 ) * 0x55 , ((c >> 4 ) & 1 ) * 0x55 , ((c >> 3 ) & 1 ) * 0x55 );
630
627
}
631
-
632
628
video_inform (VIDEO_FLAG_TYPE_SPECIAL , & timing_ega );
633
629
jega -> pallook = pallook64 ;
634
630
ega_init (& jega -> ega , 9 , 0 );
635
631
ega_set_type (& jega -> ega , EGA_SUPEREGA );
636
632
jega -> ega .priv_parent = jega ;
637
633
mem_mapping_add (& jega -> ega .mapping , 0xa0000 , 0x20000 , ega_read , NULL , NULL , ega_write , NULL , NULL , NULL , MEM_MAPPING_EXTERNAL , & jega -> ega );
634
+ /* I/O 3DD and 3DE are used by Oki if386 */
635
+ io_sethandler (0x03b0 , 0x002c , jega_in , NULL , NULL , jega_out , NULL , NULL , jega );
636
+ jega -> regs [RMOD1 ] = 0x48 ;
637
+ }
638
638
639
- io_sethandler (0x03b0 , 0x0030 , jega_in , NULL , NULL , jega_out , NULL , NULL , jega );
639
+ static void *
640
+ jega_standalone_init (const device_t * info )
641
+ {
642
+ jega_t * jega = calloc (1 , sizeof (jega_t ));
640
643
641
- jega -> regs [RMOD1 ] = 0x48 ;
644
+ rom_init (& jega -> bios_rom , JEGA_PATH_BIOS , 0xc0000 , 0x8000 , 0x7fff , 0 , 0 );
645
+ memset (& jega -> jfont_dbcs_16 , 0 , DBCS16_FILESIZE );
646
+ LoadFontxFile (JEGA_PATH_FONTDBCS , jega );
647
+
648
+ jega_commoninit (jega );
642
649
643
650
return jega ;
644
651
}
@@ -665,10 +672,10 @@ jega_close(void *priv)
665
672
fprintf (f , "Regs %02X: %4X\n" , i , jega -> regs [i ]);
666
673
for (int i = 0 ; i < 32 ; i ++ )
667
674
fprintf (f , "Attr %02X: %4X\n" , i , jega -> attrregs [i ]);
668
- for (int i = 0 ; i < 16 ; i ++ )
669
- fprintf (f , "JEGAPal %02X: %4X\n" , i , jega -> egapal [i ]);
670
- for (int i = 0 ; i < 16 ; i ++ )
671
- fprintf (f , "EGAPal %02X: %4X\n" , i , jega -> ega .egapal [i ]);
675
+ for (int i = 0 ; i < 16 ; i ++ )
676
+ fprintf (f , "JEGAPal %02X: %4X\n" , i , jega -> egapal [i ]);
677
+ for (int i = 0 ; i < 16 ; i ++ )
678
+ fprintf (f , "EGAPal %02X: %4X\n" , i , jega -> ega .egapal [i ]);
672
679
for (int i = 0 ; i < 64 ; i ++ )
673
680
fprintf (f , "RealPal %02X: %4X\n" , i , jega -> pallook [i ]);
674
681
fclose (f );
@@ -683,7 +690,7 @@ jega_close(void *priv)
683
690
fwrite (& ram [0x0 ], 0x500 , 1 , f );
684
691
fclose (f );
685
692
}
686
- // jega_log ("jeclosed %04X:%04X DS %04X\n", cs >> 4, cpu_state.pc, DS);
693
+ pclog ("jeclosed %04X:%04X DS %04X\n" , cs >> 4 , cpu_state .pc , DS );
687
694
#endif
688
695
if (jega -> ega .eeprom )
689
696
free (jega -> ega .eeprom );
@@ -706,7 +713,7 @@ jega_speed_changed(void *priv)
706
713
}
707
714
708
715
static int
709
- jega_available (void )
716
+ jega_standalone_available (void )
710
717
{
711
718
return (rom_present (JEGA_PATH_BIOS ) && rom_present (JEGA_PATH_FONTDBCS ));
712
719
}
@@ -716,10 +723,124 @@ const device_t jega_device = {
716
723
.internal_name = "jega" ,
717
724
.flags = DEVICE_ISA ,
718
725
.local = 0 ,
719
- .init = jega_init ,
726
+ .init = jega_standalone_init ,
727
+ .close = jega_close ,
728
+ .reset = NULL ,
729
+ .available = jega_standalone_available ,
730
+ .speed_changed = jega_speed_changed ,
731
+ .force_redraw = NULL ,
732
+ .config = NULL
733
+ };
734
+
735
+ static uint8_t p65idx = 0 ;
736
+ static uint8_t p3de_idx = 0 ;
737
+ static uint8_t p65 [6 ];
738
+ static uint8_t p3de [0x30 ];
739
+
740
+
741
+ static uint8_t
742
+ if386_p6x_read (uint16_t port , void * priv )
743
+ {
744
+ uint8_t ret = INVALIDACCESS8 ;
745
+ if (port == 0x63 ) {
746
+ ret = p65idx ;
747
+ } else if (port == 0x65 ) {
748
+ ret = p65 [p65idx ];
749
+ }
750
+ // pclog("p%x_r: [%04x:%04x] [%02x]%02x\n", port, cs >> 4, cpu_state.pc , p65idx, ret);
751
+ return ret ;
752
+ }
753
+
754
+ /*
755
+ OKi if386AX/SX Power management and Miscellaneous
756
+ I/O 63h: Index 0-5, I/O 65h: Data
757
+ Index 2:
758
+ Bit 3: Caps Lock enabled
759
+ Bit 2: Num Lock enabled
760
+ Bit 1: Scrl Lock enabled
761
+ Bit 0: Kana Lock enabled
762
+ Index 3
763
+ Bit 2: External monitor output enabled
764
+ Bit 1: Floppy drive 1 active
765
+ Bit 0: Floppy drive 0 active
766
+ Index 5
767
+ Bit 8: ? (1=Disabled, 0=Enabled)
768
+ Bit 7: Screen Off? (enabled by Ctrl + Alt + [1] and disabled by any key)
769
+ Bit 4: Shutdown? (caused by POST rebooting and POWER OFF command in DOS 3.21)
770
+ Bit 3: ?
771
+ */
772
+ static void
773
+ if386_p6x_write (uint16_t port , uint8_t val , void * priv )
774
+ {
775
+ jega_t * jega = (jega_t * ) priv ;
776
+ // pclog("p%x_w: [%04x:%04x] val=%02x\n", port, cs >> 4, cpu_state.pc, val);
777
+ if (port == 0x63 && val < 6 )
778
+ p65idx = val ;
779
+ if (port == 0x65 ) {
780
+ // pclog("p65_w: [%04x:%04x] idx=%02x, val=%02x\n", cs >> 4, cpu_state.pc, p65idx, val);
781
+ p65 [p65idx ] = val ;
782
+ if (p65idx == 0x03 ) {
783
+ if (val & 0x04 ) { /* Color monitor */
784
+ for (int c = 0 ; c < 256 ; c ++ ) {
785
+ pallook64 [c ] = makecol32 (((c >> 2 ) & 1 ) * 0xaa , ((c >> 1 ) & 1 ) * 0xaa , (c & 1 ) * 0xaa );
786
+ pallook64 [c ] += makecol32 (((c >> 5 ) & 1 ) * 0x55 , ((c >> 4 ) & 1 ) * 0x55 , ((c >> 3 ) & 1 ) * 0x55 );
787
+ pallook16 [c ] = makecol32 (((c >> 2 ) & 1 ) * 0xaa , ((c >> 1 ) & 1 ) * 0xaa , (c & 1 ) * 0xaa );
788
+ pallook16 [c ] += makecol32 (((c >> 4 ) & 1 ) * 0x55 , ((c >> 4 ) & 1 ) * 0x55 , ((c >> 4 ) & 1 ) * 0x55 );
789
+ if ((c & 0x17 ) == 6 )
790
+ pallook16 [c ] = makecol32 (0xaa , 0x55 , 0 );
791
+ }
792
+ } else { /* Monochrome LCD */
793
+ for (int c = 0 ; c < 256 ; c ++ ) {
794
+ int cval = 0 ;
795
+ if (c & 0x0f )
796
+ cval = ((c & 0x0e ) * 0x10 ) + 0x1f ;
797
+ pallook64 [c ] = makecol32 (cval , cval , cval );
798
+ pallook16 [c ] = makecol32 (cval , cval , cval );
799
+ }
800
+ }
801
+ jega_recalctimings (jega );
802
+ } else if (p65idx == 0x05 ) {
803
+ if (val & 0x10 ) { /* Power off (instead this call hardware reset here) */
804
+ resetx86 ();
805
+ }
806
+ }
807
+ }
808
+ return ;
809
+ }
810
+
811
+ static void *
812
+ if386jega_init (const device_t * info )
813
+ {
814
+ jega_t * jega = calloc (1 , sizeof (jega_t ));
815
+
816
+ rom_init (& jega -> bios_rom , IF386_PATH_VBIOS , 0xc0000 , 0x8000 , 0x7fff , 0 , 0 );
817
+ memset (& jega -> jfont_dbcs_16 , 0 , DBCS16_FILESIZE );
818
+ LoadFontxFile (JEGA_PATH_FONTDBCS , jega );
819
+
820
+ jega_commoninit (jega );
821
+
822
+ io_sethandler (0x0063 , 1 , if386_p6x_read , NULL , NULL , if386_p6x_write , NULL , NULL , jega );
823
+ io_sethandler (0x0065 , 1 , if386_p6x_read , NULL , NULL , if386_p6x_write , NULL , NULL , jega );
824
+ // io_sethandler(0x03dd, 2, if386_p6x_read, NULL, NULL, if386_p6x_write, NULL, NULL, jega);
825
+
826
+ return jega ;
827
+ }
828
+
829
+ static int
830
+ if386jega_available (void )
831
+ {
832
+ return (rom_present (IF386_PATH_VBIOS ) && rom_present (JEGA_PATH_FONTDBCS ));
833
+ }
834
+
835
+ const device_t if386jega_device = {
836
+ .name = "JEGA (if386AX)" ,
837
+ .internal_name = "if386jega" ,
838
+ .flags = DEVICE_ISA ,
839
+ .local = 0 ,
840
+ .init = if386jega_init ,
720
841
.close = jega_close ,
721
842
.reset = NULL ,
722
- .available = jega_available ,
843
+ .available = if386jega_available ,
723
844
.speed_changed = jega_speed_changed ,
724
845
.force_redraw = NULL ,
725
846
.config = NULL
0 commit comments