Previous Thread
Next Thread
Print Thread
Page 6 of 11 1 2 4 5 6 7 8 10 11
Joined: Mar 2001
Posts: 17,215
Likes: 234
R
Very Senior Member
Online Content
Very Senior Member
R
Joined: Mar 2001
Posts: 17,215
Likes: 234
Neat.

Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
OP Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
Thanks, RB!

I think I've got the saving the printed page nearly figured out. Here's some samples from apple II printographer printing to the Apple Scribe.

(The colors don't quite match up to the apple's color palette)

Printographer wants violet to be ribbons 2+3 but that makes it dark purple, just ribbon 2 (magenta) makes a good purple.

Apple from Zoom Graphics Disk:

[Linked Image from i.imgur.com]
[Linked Image from i.imgur.com]

Olympics from Joe Drish pictures:

[Linked Image from i.imgur.com]

Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
OP Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
I was trying to clean up my code and put some things into the luaprinter constructor so they would be done automatically done, but it seems to make it not work. So strange. And printfs in the constructor don't appear until I exit mame.


The printfs that make "Scooby 8510" and "Scooby 8511" don't appear until exiting mame, yet the initvalue gets set properly to 3333.

But if I move routines into the constructor all sorts of weird things happen. So I'll leave it outside for now since I've been fiddling with this for a day...gcc problems on Ubuntu?


Code
luaprinter(device_t & thisdevice, int testvalue){ 
        m_lp_mydevice = &thisdevice; 
        time(&m_lp_session_time);  
        initvalue = testvalue;
        printf("\n\nInit Luaprinter Scooby %d\n",testvalue);
        initvalue = 33333;
        };



Code
[MAME]> lp = manager:machine().printers for i=1,#lp do print( lp[i]:getprintername(), #lp, lp[i]:getinitvalue(), lp[i]:simplename()) end
2020-09-16 08-25-19 apple2p-sl1-parallel-pic_ctx-luaprinter	3	33333	apple2p a2bus_slot a2pic centronics centronics_luaprinter centronics
2020-09-16 08-25-19 apple2p-sl2-ssc-ssc_rs232-luaprinter	3	33333	apple2p a2bus_slot a2ssc rs232 serial_luaprinter rs232
2020-09-16 08-25-19 apple2p-sl4-parallel-pic_ctx-ap2000	3	33333	apple2p a2bus_slot a2pic centronics ap2000 centronics


(exit mame here)

[MAME]> 

Init Luaprinter Scooby 8510

Init Luaprinter Scooby 8511

Init Luaprinter Scooby 810
Average speed: 100.00% (31 seconds)
sdl_kill: closing audio
Enter sdlwindow_exit
Leave sdlwindow_exit

after putting code in the constructor I get strange behavior:

Code
[MAME]> print( manager:machine().luaprinters[1]:getprintername(), #manager:machine().luaprinters)
error: 	std::bad_alloc
[MAME]> print( #manager:machine().luaprinters)
56

Joined: Mar 2006
Posts: 1,079
Likes: 6
L
Very Senior Member
Online Content
Very Senior Member
L
Joined: Mar 2006
Posts: 1,079
Likes: 6
Does the lua interface allow you to force fflush on stdout and stderr? I know there's some really bizarre issues in mingw/msys2 with stderr not fflush()ing itself instantly (like it does on POSIX systems) on windows.

LN


"When life gives you zombies... *CHA-CHIK!* ...you make zombie-ade!"
Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
OP Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
Hi LN,

Yes, fflush(stdout); does the trick. Thanks.

so I'm just curious now why there's so many printf's when I should only have 3 luaprinter devices
Code
luaprinter::luaprinter(device_t& thisdevice, int testvalue){ 
	m_lp_mydevice = &thisdevice; 
	time(&m_lp_session_time);  
	initvalue = testvalue;
	printf("yes you can");        // putting in a printf here
	fflush(stdout);
	
	};

Code
 ./mame64 apple2p  -sl1 parallel -sl1:parallel:pic_ctx luaprinter -flop1 ../../printographer.dsk -sl2 ssc -sl2:ssc:ssc_rs232 luaprinter -sl4 parallel -sl4:parallel:pic_ctx ap2000 -verbose

yes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canyes you canAttempting load of mame.ini
...

    _/      _/    _/_/    _/      _/  _/_/_/_/
   _/_/  _/_/  _/    _/  _/_/  _/_/  _/       
  _/  _/  _/  _/_/_/_/  _/  _/  _/  _/_/_/    
 _/      _/  _/    _/  _/      _/  _/         
_/      _/  _/    _/  _/      _/  _/_/_/_/    

mame 0.224	
Copyright (C) Nicola Salmoria and the MAME team

Lua 5.3	
Copyright (C) Lua.org, PUC-Rio

...
yes you canyes you canyes you canAttempting load of raster.ini
Attempting load of source/apple2.ini
Attempting load of apple2.ini
Attempting load of apple2p.ini
yes you canyes you canyes you canAvailable videodrivers: x11 wayland dummy 

Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
OP Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
So my concept is to use the luaprinter class to provide a way to save the bitmap from a driver that doesn't really need the lua parts, just the printing parts. The lua stuff is there, but the driver doesn't need to use them.


So we can inheirit from luaprinter:

Code
class epson_lx810l_device :
public device_t, 
public device_centronics_peripheral_interface, 
public luaprinter
{
...

epson_lx810l_device::epson_lx810l_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
        device_t(mconfig, type, tag, owner, clock),
        device_centronics_peripheral_interface(mconfig, *this),
        luaprinter(*this, 810),
... 

and then we can do some things in the device_start:

Code
void epson_lx810l_device::device_start()
{
	m_online_led.resolve();

	m_cr_timer = timer_alloc(TIMER_CR);

	m_screen->register_screen_bitmap(m_bitmap);
	m_bitmap.fill(0xffffff); /* Start with a clean white piece of paper */


// do the luaprinter stuff, I would like to do more in the constructor, but it seems to cause problems.

	register_bitmap(m_bitmap);  // register with luaprinter
	luaprinterlist.emplace_back(static_cast<luaprinter *>(this));
	setprintername(sessiontime()+std::string(" ")+tagname());



and then you can save the bitmap with:

MAME]> print(manager:machine().lp[3]:pageheight())
576
[MAME]> print(manager:machine().lp[3]:pagewidth())
1024
[MAME]> manager:machine().lp[3]:savepage()
[MAME]> print(manager:machine().lp[3]:getprintername())
2020-09-16 13-53-53 apple2p-sl4-parallel-pic_ctx-ap2000
[MAME]>

So here's the page saved out:
[Linked Image from i.imgur.com]

Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
OP Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
and the luaprinter code is actually pretty short:

Code

#ifndef MAME_LUAPRINTER_H
#define MAME_LUAPRINTER_H

#pragma once

#include "emu.h"
#include "png.h"
#include "emuopts.h"

class luaprinter {

public:

	int initvalue;
	device_t * m_lp_mydevice;
	luaprinter(device_t & thisdevice, int testvalue);

	static std::vector<luaprinter *> luaprinterlist;

	const static int BUFFERSIZE = 128000;
	std::array<unsigned char, BUFFERSIZE>  m_printerbuffer;
	int m_lp_head = 0;
	int m_lp_tail = 0;
	bitmap_rgb32 *m_lp_bitmap;  // pointer to bitmap
	int m_xpos = 0;
	int m_ypos = 0;
	std::string m_luaprintername;
	int m_page_count;
	static time_t m_lp_session_time;

	void addtolist(luaprinter & myprinter){ luaprinterlist.emplace_back(& myprinter);}
	void setprintername(std::string name){ m_luaprintername = name; }
	std::string getprintername(){ return m_luaprintername; }

	int getinitvalue(){ return initvalue; }

	void clearpage(){ m_lp_bitmap->fill(0xffffff);};
	void drawpixel(int x, int y, int pixelval) { m_lp_bitmap->pix32(y,x) = pixelval; };
	int getpixel(int x, int y){return m_lp_bitmap->pix32(y,x);};
	void setheadpos(int x, int y){m_xpos=x;m_ypos=y;};

	int pagewidth() { return m_lp_bitmap->width(); }
	int pageheight() { return m_lp_bitmap->height(); }

	device_t* getrootdev();
	void savepage();
	
	std::tuple<std::array<unsigned char,BUFFERSIZE>&,int,int>  getbuffer() { return std::make_tuple(std::ref(m_printerbuffer),m_lp_head,m_lp_tail);};   
	int getnextchar();
	void putnextchar(int c);
	void register_bitmap(bitmap_rgb32 &mybitmap){m_lp_bitmap = &mybitmap;}
	std::tuple<int,int>getheadpos() { return std::make_tuple(m_xpos,m_ypos); };
	int count(){ return luaprinterlist.size();}
	std::string fixcolons(std::string in);
	std::string sessiontime();
	std::string tagname();
	std::string simplename();
};


#endif  // MAME_LUAPRINTER_H

luaprinter.cpp:
Code

#include "luaprinter.h"

luaprinter::luaprinter(device_t& thisdevice, int testvalue){ 
	m_lp_mydevice = &thisdevice; 
	time(&m_lp_session_time);  
	initvalue = testvalue;
	printf("yes you can");
	fflush(stdout);
	
	};

int luaprinter::getnextchar() {
	if (m_lp_head==m_lp_tail) return -1; 
	else {
		int retval = m_printerbuffer.at(m_lp_tail++); 
		m_lp_tail %= BUFFERSIZE; 
		return retval;
	}
}

void luaprinter::putnextchar(int c) {
	m_printerbuffer.at(m_lp_head++)=c; 
	m_lp_head %= BUFFERSIZE;
}

std::string luaprinter::fixcolons(std::string in) {
    std::string final;
    for(std::string::const_iterator it = in.begin(); it != in.end(); ++it)
    {
        if((*it) != ':')
        {
            final += *it;
        }
        else final += '-';
    }
    return final;
}

std::string luaprinter::sessiontime() {
   struct tm *info;
   char buffer[120];
   info = localtime( &m_lp_session_time );
   strftime(buffer,120,"%Y-%m-%d %H-%M-%S", info);
   return std::string(buffer);
}

std::string luaprinter::tagname() {
	device_t * dev;
	device_t * lastdev;
	dev = m_lp_mydevice;
	std::string s(dev->owner()->shortname());
	while (dev) {
		lastdev = dev;
		dev=dev->owner();
	}
	lastdev=lastdev; // complains about non use
	return fixcolons(std::string(lastdev->shortname())+std::string(m_lp_mydevice->tag()));
}

std::string luaprinter::simplename() {
	device_t * dev;
	device_t * lastdev;
	dev = m_lp_mydevice;
	std::string s(dev->owner()->shortname());
	while (dev){
		s=std::string(dev->shortname())+std::string(" ")+s;
		lastdev = dev;
		dev=dev->owner();
	}
	lastdev=lastdev; // complains about non use
	return s;
}

device_t* luaprinter::getrootdev(){
	device_t* dev;
	device_t* lastdev = NULL;
	dev = m_lp_mydevice;
	while (dev){
		lastdev = dev;
		dev=dev->owner();
	}
	lastdev=lastdev; // complains about non use
	return lastdev;
}

void luaprinter::savepage(){
    emu_file file(std::string(m_lp_mydevice->machine().options().snapshot_directory()) + std::string("/") +
				std::string(getrootdev()->shortname() ) + std::string("/"), 
				OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
    auto const filerr = file.open(std::string(getprintername())+" Page "+std::to_string(m_page_count++)+".PNG");

    if (filerr == osd_file::error::NONE)
        {
            static const rgb_t png_palette[] = { rgb_t::white(), rgb_t::black() };
            // save the paper into a png
            png_write_bitmap(file, nullptr, (bitmap_t &) (* m_lp_bitmap), 2, png_palette);
        }
}



in luaengine.cpp:
Code
        auto luaprinter_type = sol().registry().create_simple_usertype<luaprinter>("new", sol::no_constructor);
        luaprinter_type.set("clearpage", &luaprinter::clearpage);
        luaprinter_type.set("drawpixel", &luaprinter::drawpixel);
        luaprinter_type.set("getpixel", &luaprinter::getpixel);
        luaprinter_type.set("setheadpos", &luaprinter::setheadpos);
        luaprinter_type.set("savepage", &luaprinter::savepage);
        luaprinter_type.set("getbuffer", &luaprinter::getbuffer);
        luaprinter_type.set("getnextchar", &luaprinter::getnextchar);
        luaprinter_type.set("putnextchar", &luaprinter::putnextchar);
        luaprinter_type.set("getheadpos", &luaprinter::getheadpos);
        luaprinter_type.set("setprintername", &luaprinter::setprintername);
        luaprinter_type.set("getprintername", &luaprinter::getprintername);
        luaprinter_type.set("fixcolons", &luaprinter::fixcolons);
        luaprinter_type.set("sessiontime", &luaprinter::sessiontime);
        luaprinter_type.set("simplename", &luaprinter::simplename);
        luaprinter_type.set("tagname", &luaprinter::tagname);
        luaprinter_type.set("count", &luaprinter::count);
        luaprinter_type.set("getinitvalue", &luaprinter::getinitvalue);
        luaprinter_type.set("pagewidth", &luaprinter::pagewidth);
        luaprinter_type.set("pageheight", &luaprinter::pageheight);

	sol().registry().set_usertype("luaprinter", luaprinter_type);




         machine_type.set("lp", sol::property([this](running_machine &m) {
                        sol::table table = sol().create_table();
                        int i=1;
                        for(auto p : luaprinter::luaprinterlist)
                        {
                        	table[i++] = p;
                        };
                        return table;
                }));

Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
OP Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172

I thought, why not try to send the printed PNG to the printer:


dofile('../../luaprinter2.lua') -- start up my imagewriter interpreter

(print something to the page)

manager:machine().lp[1]:savepage()
print(manager:machine().lp[1]:getprintername())
os.execute('lpr ~/"Downloads/mamegit/mame/snap/ct486/2020-09-18 08-59-47 ct486-board4-lpt-lpt-centronics-luaprinter Page 0.PNG"')

and lpr sends the PNG file to the printer.

Ubuntu uses cups, I don't know how it would work on windows.

Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
OP Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
So if I add to my list of printers in the constructor, I get a whole bunch of devices in my list.

It seems to be initializing a bunch of devices that don't actually get used. It must be enumerating every possible device that uses the luaprinter.

Code
luaprinter::luaprinter(device_t& thisdevice, int testvalue){ 
	m_lp_mydevice = &thisdevice; 
	time(&m_lp_session_time);  
	initvalue = testvalue;

	addtoprinterlist( *this);
	printf("yes you can");
	printf(" device = %s ",thisdevice.tag());
	fflush(stdout);
	printf("count = %d\n",count());  // the size of the printerlist
	fflush(stdout);
	
	};

with one luaprinter device I get 19 items:

Code
./mame64 ct486   -hard1 hd128MB  -debug  -board4:lpt:lpt:centronics luaprinter -confirm_quit -ramsize 64M 
-board3:ide:ide:1 hdd -hard2 hd128MBpt -board3:ide:ide:1 hdd
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 1
...
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 9
    _/      _/    _/_/    _/      _/  _/_/_/_/
   _/_/  _/_/  _/    _/  _/_/  _/_/  _/       
  _/  _/  _/  _/_/_/_/  _/  _/  _/  _/_/_/    
 _/      _/  _/    _/  _/      _/  _/         
_/      _/  _/    _/  _/      _/  _/_/_/_/    

mame 0.224	
Copyright (C) Nicola Salmoria and the MAME team

Lua 5.3	
Copyright (C) Lua.org, PUC-Rio

yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 10
yes you can device = :board2:comat:serport0:luaprinter count = 11
yes you can device = :board2:comat:serport1:luaprinter count = 12
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 13
yes you can device = :board4:lpt:lpt:centronics:ap2000 count = 14
yes you can device = :board4:lpt:lpt:centronics:lx810l count = 15
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 16
Debug Build: Disabling input grab for -debug
Debug Build: Disabling input grab for -debug
Debug Build: Disabling input grab for -debug
[MAME]> 
"hd128MB" approximately matches the following
supported software items (best match first):


"hd128MBpt" approximately matches the following
supported software items (best match first):

DEVICE START CALL luaprinterlist

DEVICE START CALL luaprinterlist

DEVICE START CALL setprintername

DEVICE RESET CALLED
DEVICE RESET CALLED


MAME debugger version 0.224 (mame0224-205-g69406ddcc71-dirty)
Currently targeting ct486 (PC/AT 486 with CS4031 chipset)
[MAME]> yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 18
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 19

and if I add a second luaprinter device I get 35 total devices.


Code
/mame64 ct486  -hard1 hd128MB  -debug  -board4:lpt:lpt:centronics luaprinter -confirm_quit -ramsize 64M
 -board3:ide:ide:1 hdd -hard2 hd128MBpt -board3:ide:ide:1 hdd -board2:comat:serport1 luaprinter
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 1
...
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 8
yes you can device = :board2:comat:serport1:luaprinter count = 9
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 10
yes you can device = :board2:comat:serport1:luaprinter count = 11
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 12
yes you can device = :board2:comat:serport1:luaprinter count = 13
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 14
yes you can device = :board2:comat:serport1:luaprinter count = 15
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 16
yes you can device = :board2:comat:serport1:luaprinter count = 17
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 18
yes you can device = :board2:comat:serport1:luaprinter count = 19
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 20
    _/      _/    _/_/    _/      _/  _/_/_/_/
   _/_/  _/_/  _/    _/  _/_/  _/_/  _/       
  _/  _/  _/  _/_/_/_/  _/  _/  _/  _/_/_/    
 _/      _/  _/    _/  _/      _/  _/         
_/      _/  _/    _/  _/      _/  _/_/_/_/    

mame 0.224	
Copyright (C) Nicola Salmoria and the MAME team

Lua 5.3	
Copyright (C) Lua.org, PUC-Rio

yes you can device = :board2:comat:serport1:luaprinter count = 21
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 22
yes you can device = :board2:comat:serport0:luaprinter count = 23
yes you can device = :board2:comat:serport1:luaprinter count = 24
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 25
yes you can device = :board4:lpt:lpt:centronics:ap2000 count = 26
yes you can device = :board4:lpt:lpt:centronics:lx810l count = 27
yes you can device = :board2:comat:serport1:luaprinter count = 28
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 29
Debug Build: Disabling input grab for -debug
Debug Build: Disabling input grab for -debug
Debug Build: Disabling input grab for -debug
[MAME]> 
"hd128MB" approximately matches the following
supported software items (best match first):


"hd128MBpt" approximately matches the following
supported software items (best match first):

DEVICE START CALL luaprinterlist

DEVICE START CALL luaprinterlist

DEVICE START CALL setprintername

DEVICE RESET CALLED
DEVICE RESET CALLED
m_rs232_rxbaud read=7
rs232_rxbaud read=7


MAME debugger version 0.224 (mame0224-205-g69406ddcc71-dirty)
Currently targeting ct486 (PC/AT 486 with CS4031 chipset)
[MAME]> 

>g
[MAME]> yes you can device = :board2:comat:serport1:luaprinter count = 32
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 33
yes you can device = :board2:comat:serport1:luaprinter count = 34
yes you can device = :board4:lpt:lpt:centronics:luaprinter count = 35
Average speed: 99.93% (1 seconds)

Well, I guess as long as it works I'll keep it outside the constructor.

Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
OP Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172

Just for fun, I wanted to see if I could get some color postscript output from the win95 printer drivers using the QMS Colorscript 230 drivers.

Setting the spool settings to Print directly to printer and disable bidirectional support because it would put 0x14 characters into the printout.

Using the "printer" centronics device and then using mame's File manager and setting the printout to a file to save out the data.


Once done, using gv (ghostview) under Ubuntu to view the output. (I had to apt install gv)

[Linked Image from i.imgur.com]
[Linked Image from i.imgur.com]
[Linked Image from i.imgur.com]
[Linked Image from i.imgur.com]

What I'd like to do is to figure out some way to have it watch the printer, when there's a long pause in the output, say 15 seconds or so, then save everything to a file, so it can run gv automatically.

Page 6 of 11 1 2 4 5 6 7 8 10 11

Link Copied to Clipboard
Who's Online Now
1 members (MrBogi), 303 guests, and 1 robot.
Key: Admin, Global Mod, Mod
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics9,320
Posts121,929
Members5,074
Most Online1,283
Dec 21st, 2022
Our Sponsor
These forums are sponsored by Superior Solitaire, an ad-free card game collection for macOS and iOS. Download it today!

Superior Solitaire
Forum hosted by www.retrogamesformac.com